How to search commands in PowerShell?
PowerShell cmdlets are build on Verb-Noun naming conventions. For example, Get-Service or Set-Disk. While working with PowerShell console or editor many times you need help to find the specific commands. To find the commands Get-Command cmdlet is used.
Get-Command Cmdlet
Get-Command has two parameters -Verb and -Noun. The verb means Get, Update, Set, etc and the Noun means keyword for the commands like event, service, Azure, VM, etc. When you type Get-Command in PowerShell console, commands from all the loaded modules will be displayed on the screen but we need to search the specific command.
For example, “Service” command related help, if you need to retrieve the data related to service, use Get Verb. To change the configuration or update something, use Set or Update Verb.
Below command shows the Service
Get-Command -Verb Get -Noun Service
To get the command related to Alias and verb Set.
Get-Command -Verb Set -Noun Alias
Sometimes you know only keywords but don’t know the full verb and in that case if you search the command, there will be no output. For example,
Get-Command -Verb Set -Noun event
We didn’t get the output because Set-Event command doesn’t exist. But we have turnaround for this. You can use the wildcard character(*) to search the related command. Wildcard character (*) will be covered later in the upcoming article but understand the below logic.
Event* – Search the keyword starting with Event.
*Event – Search the keyword ending with Event.
*Event* – Search the keyword containing word Event.
Example of the above explaination.
Get-Command -Verb Set -Noun *event*
The above code will show all the nouns containing keyword Event.
Another example,
Get-Command -Verb Get -Noun event*
To search the multiple commands, you can separate commands by comma (,).
Get-Command -Verb Get -Noun event*, *IPSec*
You can also retrieve parameters and parameter sets but as this article is only focusing on searching the commands, we will cover about parameters and parameter sets in the future article.