Windows PowerShell PowerShell01 Sample
This sample uses InitialSessionState to constrain a runspace and add commands and providers.
This sample will concentrate on the SDK mechanisms to restrict the runspace. Script alternatives to the SDK include $ExecutionContext.SessionState.LanguageMode and the PSSessionConfiguration cmdlets.
Sample Objectives
This sample demonstrates the following:
- Restricting the language by setting the InitialSessionState.LanguageMode property.
- Adding aliases to the environment using InitialSessionState.Commands property.
- Marking commands as private.
- Removing providers using InitialSessionState.Providers property.
- Removing commands using InitialSessionState.Commands property.
- Adding commands and providers.
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 executable will be built in the default \bin or \bin\Debug directory.
Run the sample
- Start command prompt.
- Navigate to the folder containing the sample executable.
- Run the executable.
- See the output results and the corresponding code.