PowerShell Essentials: Get-Command

by Apr 21, 2009

There are only three cmdlets you should know by heart. One is the Get-Command, which can do a lot more than you might think.

When called without parameters, it returns all cmdlets available:

Get-Command

To find cmdlets with a specific purpose, search for verb or noun. For example, to get a list of all cmdlets that get data, use this:

Get-Command -verb Get

To find all cmdlets that are related to printing, use this:

Get-Command -noun *print*

Get-Command is not limited to cmdlets. To find any "command" related to printing, use this:

Get-Command *print*

This time, the list includes any executable that PowerShell can find. This may also include entities you will never be able to use, such as link libraries (DLLs). You can filter the list with the -commandType parameter and further refine the results in the pipeline:

Get-Command *print* -commandType Application |
Where-Object { $_.definition -like '*.exe' }

Or, you can group the result based on file type:

Get-Command *print* -commandType Application |
Group-Object -property { $_.Definition.Split('.')[1] }

To find out what a specific command really "is" and how PowerShell interprets it, specify the command you want know more about:

Get-Command dir
Get-Command md

You can see all of the information Get-Command returns for any given command by piping the result to Format-List and use a star ("*") to make all properties visible:

Get-Command dir | Format-List *

Basically, Get-Command is your primary discovery tool, helping you find the command you are looking for.

Note: Microsoft has changed the default behavior for Get-Command in PowerShell v2. Here, it returns both cmdlets and functions by default whereas v1 only returned cmdlets. You can use the -commandType property to control the behavior manually. For example:

Get-Command *print* -commandType cmdlet