2.9 KiB
2.9 KiB
Windows PowerShell StopProcessSample02 Sample
This sample shows how to write a cmdlet that implements user notifications using WriteWarning, WriteVerbose, and WriteDebug. The cmdlet stops a specified process.
Sample Objectives
This sample describes the following:
- Declaring a cmdlet class.
- Declaring cmdlet parameters.
- Specifying positions for parameters.
- Specifying that the parameters can accept an object from the pipeline or accept a value from a property of an object that has the same name as the parameter.
- Handling errors and exceptions.
- Using the ShouldProcess and ShouldContinue methods.
- Implementing the Force and PassThru parameters.
- Implementing user notifications using WriteWarning, WriteVerbose, and WriteDebug.
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
- Store the assembly in the following module folder: [user]/Documents/WindowsPowerShell/Modules/StopProcessSample02
- Start Windows PowerShell.
- Run the following command:
Import-Module StopProcessSample02(This command loads the assembly into Windows PowerShell.) - Type the following command to run the cmdlet:
Stop-Proc <process name>