Get-Command – One of the best Cmdlets besides Get-Help

So laying on the sofa, sick, bored out of my mind, what better way to spend my time then writing a blog post about Get-Command. The Get-Command Cmdlet is apart of the Microsoft.PowerShell.Core module, it was introduced in PowerShell version 1.0 and is one of the most useful Cmdlets to find a command you are looking for. It has a variety of parameters that allow you to search for a command by using a combination of parameters or just using Get-Command on its own. Go ahead and run Get-Command in your console before continuing with this post. As you can see, it returns all commands that are available in your PowerShell session. Later on, we will go through several example on how we can leverage the parameters to find specifics commands.

Lets start with a basic example and then build on it to get a specific command, Get-ADUser. First, lets get all of the command that are already imported into our PowerShell session.

The output does not have any Cmdlets from the ActiveDirectory module we need to find the GetADUser. If you have RSAT Tools installed, import the module using Import-Module ActiveDirectory and re-run Get-Command -ListImported. As you can see now, a list of Active Directory Cmdlets are available. We can now start getting more complex to find Get-ADUser.

Lets get limit the scope of our command to get only the ActiveDirectory module Cmdlets that are available.

Now we filtered only the ActiveDirectory module and can now filter down even more. Get-Command has a parameter -Verb that allows us to filter by using the verb of the Cmdlet (e.g. Get, Set, Import, Reset). Lets filter by verb Get and view the output.

Great! we now have all Cmdlets that start with the verb Get. Lets keep building, another parameter -Noun. We know the prefix for most ActiveDirectory Cmdlets start with AD, so lets use the noun User and see what the output is.

Success! We found exactly the command we needed to. But did you notice the * character in the noun parameter? This is because we know the prefix is AD and the noun parameter acts as a filter, this tells PowerShell to find anything that has User in the noun. You can do the same for the parameter -Verb.

So now what? We found the command, but what else can we do with Get-Command. Besides just getting the command, we can get syntax, command info, or search by parameter type or parameter name. Lets see the syntax of Get-ADUser so we can better understand what it does.

We can now see the parameters and parameter types of each. This is a great way to understand how the Cmdlet works and how we can use it in our own code.

Now that we built our command to find just the Get-ADUser and get the syntax. Lets look at another example that searches for a certain parameter name Identity. Using the parameter ParameterName will allow us to filter through Cmdlets in the ActiveDirectory module that has an -Identity parameter.

We have found all of the command that have a parameter name of Identity. For purposes, there are a limited set listed above, the actual total number of Cmdlets that have the parameter of Identity is 117.

The last two parameters to take a look at are the -Name and -ShowCommandInfo parameters. If we already know the Cmdlet name and want to find which module it is in, we can use the -Name parameter and view the Source.

The command found the Cmdlet and is found in the ActiveDirectory module. The final parameter will build on the previous example, but we will add the -ShowCommandInfo parameter. The -ShowCommandInfo show the information pertaining to the command you a attempting to get.

Now we can see all of the information in the Get-ADUser Cmdlet, including syntax information.

We took a look at multiple examples of the Get-Command Cmdlet that can help us build tools in our scripts and module. It is a very help tool and that is why, (IMHO), it is one of the best Cmdlets to use besides Get-Help. To find out more information about Get-Command view Microsoft’s documentation.


Note: At the time of writing this post, PowerShell is in version 6. The -ShowCommandInfo parameter was introduced in PowerShell version 5.0.

Update: Get-Command was introduced in PowerShell v1.0, not 3.0. Thanks to Ryan Yates for the correction. Microsoft’s docs on Get-Command only goes back to v3.0.


About pwshliquori

Hi, I’m Chris. I am not a programmer or developer, I am a scripter that enjoys PowerShell and a glass of bourbon. 5 years deep into PowerShell, my primary focus is to automate pretty much anything I don’t like to do manually. Follow me on twitter - @pwshliquori

3 thoughts on “Get-Command – One of the best Cmdlets besides Get-Help

Comments are closed.