So you may be reading up on PowerShell and be starting to think “really what is a cmdlet?”
Well a cmdlet is pronounced command-let and it is a lightweight PowerShell script that performs one function. PowerShell comes with over 200 core cmdlets included but you can write your own or download and use ones that other people have written. Cmdlets execute code out of the .NET framework(as PowerShell is built of the .NET framework) and return an object to the next command in the pipeline.
Cmdlets are written in a verb-noun format to help describe what they do. This does make it easier in identifying what the cmdlet is used for and easier to search for the cmdlet that you need.
A cmdlet has the extension .ps1 so if you do write one you need to save it with the .ps1 extension.
If you need to access the help file for a cmdlet you can do it by typing the command Get-Help cmdletName-detailed then pressing enter to execute the command.
Some key PowerShell cmdlet terms
- Parameter set: This is a set of parameters that are used in a command to perform an action. You can have lots of parameter sets in a cmdlet but each set must have a unique parameter.
- Dynamic parameter: A dynamic parameter that is added to the cmdlet at runtime usually this is a parameter based on another the value of a different parameter.
- ShouldProcess feature: The ShouldProcess feature is to prompt the user running the PowerShell script for feedback before the script makes changes to the system, (eg. Are you sure you want to change your IP address?) . To use this the ShouldProcess feature, the cmdlet must declare that it has support for the ShouldProcess feature when the cmdlet attribute is declared.
- Transaction: A transaction is a group of commands that is treated as one single task. The task will automatically fail if any command in the sequence fails. Also when using transactions the user can finalise or undo the actions performed in the transaction, so if the sequence of commands fail the transaction will return everything to the state that it was before the transaction started. To participate in a transaction, the cmdlet must declare that it supports transactions when the Cmdlet attribute is declared. PowerShell 2.0 was when Microsoft brought out support for transactions.