I wanted to execute Exchange powershell commands using System.Management.Automation.Runspaces;
Add-PSSnapIn of Exchange 2013 was successful, but unable to execute any command. e.g: Get-Group, Get-MailBox, Enable-MailBox
Exchange 2013 SnapIn used here is "Microsoft.Exchange.Management.PowerShell.SnapIn".
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver); rc = RunspaceConfiguration.Create(); PSSnapInInfo info = rc.AddPSSnapIn(Exchange2013SnapIn, out warning); if (warning != null) { System.Console.Write(warning.Message); return; } r = RunspaceFactory.CreateRunspace(rc); r.Open(); ri = new RunspaceInvoke(r); try { System.Console.WriteLine("Executing command : " + sampleArg); resultSet = ri.Invoke("Get-Group", input, out errors); } catch (Exception e) { System.Console.WriteLine(e.Message); }Same code was working for Exchange 2007/2010 using respective SnapIn.
Is anyone facing/faced similar issue ??