How to Get PowerShell Commands Contain Specific Keyword
Problem
When you want to use PowerShell commands, you might be wondering what the exact command to use because there are too many commands. You likely just remember a keyword or a phrase. Based on this information, you want to find commands with that specific keyword.
In this blog post, we will walk you through how to find PowerShell commands that contain specific keyword.
Solution
To get list of PowerShell commands, we use Get-Command
cmdlet. Next, we need to find out the way to filter the result.
In this case, we want to find all commands containing aduser
and we use *aduser*
to specify the pattern.
Get-Command -Name *aduser*
The result will look as follows:
There are other ways to get the same result:
Get-Command | Where-Object -Property Name -like *aduser*
# or
Get-Command | Where-Object { $_.Name -like "*aduser*" }
Above script is basically the short form of fomer script.
Script Get-Command | Where-Object -Property Name -like *aduser*
basically filters the object result from Get-Command
using Where-Object
cmdlet and like
operator which is similar to SQL like
operator in order to find the commands.
Meanwhile, Get-Command | Where-Object { $_.Name -like "*aduser*" }
using script blocks to filter the Name
property. Then, it uses like
operator to find the containing commands.
Conclusion
In order to get PowerShell commands that contain specific keyword, we need to use Get-Command
and filter the object result by specifying the pattern we are searching for.