Windows PowerShell Get-Command Cmdlet

Windows PowerShell Get-Command Cmdlet

Get-Command is one of PowerShell's simpler cmdlets; I use it for researching other cmdlets.

If you are new to PowerShell, then Get-Command is a good cmdlet for practicing the basics.  For more experienced users this page will help you discover more of the 300+ PowerShell v 3.0 cmdlets.

Windows PowerShell Get-Command Topics


PowerShell Pre-requisites and Checklist

In the case of Windows 7 and later, you don’t need to download any extra files, just: ‘Add Feature’ –> Windows PowerShell.  However, for older operating systems, there are different versions of PowerShell for XP, Windows Server 2003 and Vista.  For such legacy systems only, you need to download PowerShell from Microsoft’s site.

Once you have installed PowerShell 2.0 or later, I recommend choosing the ISE (Integrated Scripting Engine) version, it will save buying a text editor.

Get-Command On Its Own

Get-Command is one of the few built-in cmdlets that returns results on its own.  However the list is so long that the art of using Get-Command is to select the best filter.

# PowerShell Get-Command

Note 1: This will return all the cmdlets and their aliases.  Maybe you need a filter?  If so see below.

Get-Command Wildcards

Example 1: Listing PowerShell commands beginning with set.

# PowerShell Get-Command Wildcard*
Get-Command Set*

Example 2: Suppose the cmdlet you are searching for begins with a letter between M and S

# PowerShell Get-Command Range
Get-Command [M-S]*

Example 3: You think it may have ‘Serv’ somewhere in the command.

# PowerShell Get-Command
Get-Command *serv*

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Get-Command with -Noun and -Verb

As you get to know PowerShell better so you become familiar with verbs such as ‘Set’ or ‘Get’ and nouns such as ‘Process’ or ‘Computer’.  This is why I now prefer to filter Get-Command with -Noun or -Verb.  One of my greatest successes was finding ‘Restart-Service’.  I had used start and stop-service, but when I tried this filter I unearthed the useful Restart-Service.

# PowerShell Get-Command Nouns
Get-Command -Noun Service

Also Verbs

# PowerShell Get-Command Nouns
Get-Command -Verb S*

Note 2: I could have chosen -Verb Set, but I wanted to show you that -Verb also take wildcards*.

Get-Command -Module

Firstly list your modules with Get-Module.  Make your selection, for example, ISE.

# PowerShell Get-Command Module info
Get-Module ISE

Here is another example which imports a modules then checks the cmdlets.

$Baskets = "PSDiagnostics"
Import-Module $Baskets
Get-Command -Module $Baskets

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Further Research on Get-Command

# PowerShell Get-Command Parameters
Get-Help Get-Command

Checking the help file may reveal useful parameters and techniques, for instance -CommandType can filter for just Aliases see here.

Talking of parameters, Get-Command can find cmdlets that support a particular parameter, for example -computerName.

# Find a PowerShell Cmdlet by Its Parameter
Get-Command | Where-Object { $_.parameters.keys -Match "Computer*"}

Here is another variation; I think the code is neater.

# Find a PowerShell Cmdlet by Its Parameter
Get-Command | Where-Object {$_.parameters.PassThru} |
Select-Object Name

You can also filter on parameter.definition.

Get-Command | Where-Object { $_.definition -Like "*Index*"}


Summary of Get-Command Cmdlet

Get-Command is a great way to research what PowerShell cmdlets exist.  It helps to filter with -Noun -Verb, you can also use * wildcards.

If you like this page then please share it with your friends


See more Windows PowerShell tutorials

PShell Home   • Introduction   • Dreams   • 3 Key Commands   • PowerShell Help About   • Get-Help

PowerShell v 3.0   • Set-ExecutionPolicy   • Get-Command   • Cmdlet scripts   • Import-Module

PowerShell Version Check   • Backtick   • PowerShell examples   • PowerShell ISE   • Get-Member

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.