Windows PowerShell Runspace 01 Sample
This sample uses the PowerShell class to run the Get-Process cmdlet synchronously. The Name and HandleCount are extracted from the objects returned by the cmdlet and displayed. Subsequent runspace samples show how to implement additional runspace functionality.
Sample Objectives
This sample demonstrates the following:
- Creating a PowerShell object to run a command.
- Adding a command to the pipeline of the PowerShell object.
- Running the command synchronously.
- Using PSObject objects to extract properties from the objects returned by the command.
Related topics
Operating system requirements
Client
Windows 8.1
Server
Windows Server 2012 R2
Build the sample
-
Start Microsoft Visual Studio and select File > Open > Project/Solution.
-
Go to the directory named for the sample, and double-click the Visual Studio Solution (.sln) file.
-
Press F7 or use Build > Build Solution to build the sample.
The library will be built in the default \bin or \bin\Debug directory.
Run the sample
- Start a Command Prompt.
- Navigate to the folder containing the sample executable.
- Run the executable.