Create(); PSSnapInException
snapInException = null;
PSSnapInInfo info =
EMSConfig.AddPSSnapIn(???Microsoft.Exchange.Management.PowerShell.Admin???,
out snapInException);
Runspace EMSRunSpace =
RunspaceFactory.CreateRunspace(EMSConfig);
EMSRunSpace. Open();
To enable the running of commands, an instance of a pipeline object must be created from the runspace
that you have already created. The pipeline object provides the ability to stream the output of one command
into the next command in the list. To create the pipeline, use the CreatePipeline method of the
runspace that you created. The CreatePipeline method has overloaded methods that enable you to
pass single commands or an entire pipeline of commands that you want to run. A simple example would
be to have the pipeline run Get-Mailbox , as follows:
Pipeline pipeLine = EMSRunSpace.CreatePipeline(???Get-Mailbox???);
Now that you have specified the command that the pipeline will execute, the Invoke method of your
pipeline object can be used to return a PSObject collection of the results of the command you ran. The
PSObject collection results can be cycled through and inspected or used elsewhere in your code.
The following example uses a foreach loop to cycle through each of the items in the returning
PSObject collection and temporarily assigns the Name property value to a string:
Collection < PSObject > cmdData = pipeLine.
Pages:
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679