- Getting Started with PowerShell
- Michael Shepard
- 314字
- 2021-07-16 20:28:22
Interpreting the cmdlet syntax
The syntax section of the cmdlet help can be overwhelming at first, so let's drill into it a bit and try to understand it in detail. I will use the get-service
cmdlet for an example, but the principles are same for any cmdlet:
The first thing to notice is that there are three different get-service
calls illustrated here. They correspond to the PowerShell concept of ParameterSets, but you can think of them as different use cases for the cmdlet. Each ParameterSet, or use case will have at least one unique parameter. In this case, the first includes the –Name
parameter, the second includes –DisplayName
, and the third has the –InputObject
parameter.
Each ParameterSet lists the parameters that can be used in a particular scenario. The way the parameter is shown in the listing, tells you how the parameter can be used. For instance, [[-Name] <String[]>]
means that the name parameter has the following attributes:
- It is optional (because the whole definition is in brackets)
- The parameter name can be omitted (because the name is in brackets)
- The parameter values can be an array (list) of strings (String[])
In general, a parameter will be shown in one of the following forms:
Applying this to the Get-Service
syntax shown previously, we see that some valid calls of the cmdlet could be: