The Get-Command cmdlet (‘command let’) in my opinion is the first PowerShell command you should know – that is if you are new to PowerShell.
What is Get-Command?
Get-Command in PowerShell lists all available PowerShell Cmdlets, Functions and Modules in your computer. I guess you are already beginning to see how helpful get-command in PowerShell can be.
This is why I said that the Get-Command is a Cmdlet you need to know. The reason is simple. If you need a Cmdlet but you don’t know the Cmdlet or you cannot remember it, Get-Command will help you find it.
How to Use Get-Command in PowerShell to Find Cmdlets
Lets say you are scripting and you want to export some output to a csv file. The great thing about PowerShell Cmdlets is that they are like normal English words in the format Verb-Noun. With this in mind you know that the Cmdlets to export to txt file or csv will begin with the word “Export” – the verb part of the Cmdlet you need. This is the power of the Get-Command in PowerShell!
To find Cmdlets that begin with the word “Export”, run the command below:
Get-Command -Verb "export"
Here is the result of the command
Before I talk about the result of the command let me digress a bit to tell you about PowerShell Parameters. Most, if not all PowerShell Cmdlets have one or two parameters (arguments).
You would have noticed that in the last command, I entered a hyphen “-” followed by the word “Verb” before I entered “Export”. The word “Verb” is a parameter of the Get-Command Cmdlet. A Cmdlet parameter allows us to filter the results produced by the Cmdlet. Adding “-Verb” parameter allowed me to inform Get-Command that I want only Cmdlets with Verb “Export”.
With that said, lets go back to the Get-Command in PowerShell.
Going back to the results of the command, notice that “Export-Csv” appears in the list – I highlighted this in the image to make it easy to spot. We have used the Get-Command in PowerShell to find the Cmdlet we require! Isn’t that great!
Exploring More Ways to Use the Get-Command in PowerShell Cmdlet
Another way you can use the Get-Command in PowerShell Cmdlet is to use the parameter “-ParameterName” to find all Cmdlets that has a particular parameter. Wondering where this might be applicable? Lets see.
Say you are scripting and you want to find all Cmdlets that have a particular parameter, say “NoTyPeInformation”, you can run the command below to get all Cmdlets with this parameter.
Get-Command -ParameterName "NoTyPeInformation"
Here is the result of the command:
That is the result of all Cmdlets currently available on my computer.
I hope you now know how to use the Get-Command Cmdlet in PowerShell. If you have any questions, you can Contact Me. I will also appreciate if you leave comments using the Leave a Reply form below.
References and Further Reading
- Powershell NoTypeInformation: Applications and Examples
- PowerShell ForEach loop: Applications with examples