A good question came up in class today. We were working with the registry and a student needed to know how to change the value of a registry property using New-PropertyItem. Well, we can’t exactly do that. Remember that PowerShell has different verbs that describe the intent of the cmdlet. The Approved Verbs for Windows PowerShell list these verbs.
- New creates
- Set changes
- Remove destroys
The verbs are there to help us find what we need. For example, what if I need to change an IP address, but I do not know the cmdlet? Try this:
Get-Command Set-*ip*. From experience, I knew that there is a good chance that IP would be in the noun. From the verb list, I know to look for “Set” verbs. Here is the difference.
PS C:\> Get-Command set-*ip* | Measure-Object | Select -ExpandProperty Count
20
PS C:\> Get-Command *ip* | Measure-Object | Select -ExpandProperty Count
187
The first number, 20, shows how many possible cmdlets returned when you know to use the “Set” verb. Without it, you would have to look at 187 cmdlets.
Take the time to get to know the PowerShell verbs. they will help make your PowerShell usage much more efficient and effective.
Comments