This sample shows how to add a module to an InitialSessionState object so that the module is loaded when the runspace is opened. The module provides a Get-Proc cmdlet (defined by the GetProcessSample02 Sample) that is run synchronously by using a PowerShell object.
This sample requires Windows PowerShell 2.0.
This sample demonstrates the following.
Creating an InitialSessionState object.
Adding the module to the InitialSessionState object.
Creating a Runspace object that uses the InitialSessionState object.
Creating a PowerShell object that uses the runspace.
Adding the module’s get-proc cmdlet to the pipeline of the PowerShell object.
Running the command synchronously.
Extracting properties from the PSObject objects returned by the command.
This sample creates a runspace that uses an InitialSessionState object to define the elements that are available when the runspace is opened. In this sample, a module that defines a Get-Proc cmdlet is added to the initial session state.
Other ResourcesWriting a Windows PowerShell Host Application