Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the command to access Exchange Management Tools from C# code in Exchange 2010
    primarykey
    data
    text
    <p>In Exchange 2007 this line of code is used to load the Exchange Poweshell commands snapin:</p> <pre><code>PSSnapInInfo info = rsConfig.AddPSSnapIn( "Microsoft.Exchange.Management.PowerShell.Admin", out snapInException); </code></pre> <p>However, this does not exist in Exchange 2010 and I am pulling my hair out trying to find out how to access the Exchange Powershell commands from C# code. Microsoft.Exchange.Management.PowerShell.Admin does not exist anywhere on the Exchange Server and I can find nothing on Google that talks about an equivalent line of code.</p> <p>How do I access Exchange Management Tools from C# code in Exchange 2010?</p> <p>Below is my complete code for reference, it all works until I add the line of code:</p> <pre><code> //Creating and Opening a Runspace RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn( "Microsoft.Exchange.Management.PowerShell.Admin", out snapInException); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig); myRunSpace.Open(); //How Do I Run a Cmdlet? //create a new instance of the Pipeline class Pipeline pipeLine = myRunSpace.CreatePipeline(); //create an instance of the Command class // by using the name of the cmdlet that you want to run Command myCommand = new Command(txtCommand.Text); //add the command to the Commands collection of the pipeline pipeLine.Commands.Add(myCommand); Collection&lt;PSObject&gt; commandResults = pipeLine.Invoke(); // iterate through the commandResults collection // and get the name of each cmdlet txtResult.Text = "start ...."; foreach (PSObject cmdlet in commandResults) { string cmdletName = cmdlet.Properties["Name"].Value.ToString(); System.Diagnostics.Debug.Print(cmdletName); txtResult.Text += "cmdletName: " + cmdletName; } txtResult.Text += ".... end"; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload