Using Get-Command in PowerShell

Something that I use very often is Get-Command. It shows you what module the cmdlet is from, what cmdlets a module has, etc. In this last blog post of 2024, I will show you how it works 🙂

What is Get-Command?

“The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, filters, scripts, and applications. Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter.

Without parameters, Get-Command gets all the cmdlets, functions, and aliases installed on the computer. Get-Command * gets all types of commands, including all the non-PowerShell files in the Path environment variable ($env:PATH), which it lists in the Application command type.

Get-Command that uses the exact name of the command, without wildcard characters, automatically imports the module that contains the command so that you can use the command immediately. To enable, disable, and configure automatic importing of modules, use the $PSModuleAutoLoadingPreference preference variable. For more information, see about_Preference_Variables.

Get-Command gets its data directly from the command code, unlike Get-Help, which gets its information from help topics.

Starting in Windows PowerShell 5.0, results of the Get-Command cmdlet display a Version column by default. A new Version property has been added to the CommandInfo class.”

Source: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-command?view=powershell-7.4

Parameters

In the chapters below, I will cover the Parameters for Get-Command:

All

Using the -All Parameter, Get-Command will return all commands, including commands of the same type with the same name. Depending on how many modules you have installed, this could take some time to process 🙂 On my system, it took 50 seconds to count the 98430 (!) cmdlets.

CommandType

When using the -CommandType Parameter, you can search for specific types of cmdlets. Valid types are:

  • Alias, this will retrieve the aliases of all PowerShell commands
  • All, this will return all kinds, and if the same as using *
  • Application, this will search in the $Env:Path / $Env:PatheXT for non-PowerShell executable files.
  • Cmdlet, returned all cmdlets
  • ExternalScript, returns all .ps1 files in the $Env:Path variable.
  • Filter, returns all simple and advanced Filters
  • Function, returns all simple and advanced Functions.
  • Script, returns all Script Blocks and should be used with the ExternalScript value to scan all .ps1 files.

You can use multiple values separated by a comma; for example, Get-Command -CommandType ExternalScript, Script will return all the Script Blocks inside the .ps1 file in $Env:path.

FullyQualifiedModule

Using the -FullyQualifiedModule Parameter, you can specify a module name, full module specification, or the path to a module file. This can’t be used with the -Module Parameter.

FuzzyMinimumDistance

The -FuzzyMinimumDistance Parameter allows you to be more or less accurate in your search. Using this, with the Uint32 type, you can get more accurate results with a lower value, with 0 being an exact match.

ListImported

Using the -ListImported Parameter, you can only display all the commands from the current session. This would return all basis cmdlets, including mkdir, prompt, drive letters, etc., and everything from the Functions and Modules imported by your PowerShell profile.

Module

With the -Module Parameter, you can specify an array of modules to retrieve the cmdlets. For example, Get-Command -Module Microsoft.Graph.Sites, Microsoft.Graph.Teams would return the cmdlets for both modules. This can’t be used with the -FullyQualifiedModule Parameter.

Name

You can specify an array of names using the -Name Parameter, and Get-Command will return information for those if found. Wildcards are allowed, and if two cmdlets have the same name, Get-Command will return the information for the one that runs when you type the cmdlet’s name. For example, Get-Command -Name Get-VM, Get-Host will return two cmdlets with their source module name.

Noun

Using the -Noun Parameter, you can let Get-Command return all cmdlets, Functions, or Aliases that include the specified noun or nouns. You can select one or more, including wildcards. For example, Get-Command -Noun JSON, XML will return all the ConvertFrom-XML, ConvertFrom-JSON but also the ConvertTo-XML, ConvertToJSON cmdlets, etc.

ParameterSetName

Using the -ParameterSetName Parameter, you can get all commands in the session using the specified parameters. You can enter Name, Aliases, or Wildcards.

ParameterSetType

Using the -ParameterSetType Parameter, you can get all commands in the session that have Parameters using the specified Type. You can enter Name, Aliases, or Wildcards.

ShowCommandInfo

When using the -ShowCommandInfo Parameter, Get-Command will return more information on the cmdlets found, including Parameters and Parameter Sets.

Syntax

Using the -Syntax Parameter, Get-Command will return the following data about the cmdlets: Aliases, Cmdlets, Functions and Filters, Scripts, Applications, or Files.

TotalCount

With the -TotalAcount Parameter, you can limit the number of cmdlets returned. For example, Get-Command -Name ConvertFrom-* -TotalCount 1 would only return the first one found instead of the 112 on my system.

UseAbbreviationExpansion

Using the -UseAbbreviationExpansion Parameter, you can match the characters you supplied to an upper-case character in the result. For example, Get-Command -UseAbbreviationExpansion i-psdf would match Import-PowerShellDataFile.

UseFuzzyMatching

Using the -UseFuzzyMatching Parameter, you will use a fuzzy matching algorithm to find cmdlets. The output will be ordered from the closest match to the least likely match. It can’t be used together with wildcards.

Verb

Similar to the -Noun Parameter, the -Verb Parameter can be used to find cmdlets, Functions, and Aliases based on how the array of verbs is supplied. For example, Get-Command -Verb Select, Show returns all cmdlets that start with either Select or Show.

Examples

In the chapters below are a few examples I often use to discover things.

Get all cmdlets for a specific module

In the example below, I use Get-Command to retrieve all cmdlets from the Microsoft.Graph.Teams module:

Find out from what Module a specific cmdlet is from

In the example below, I use Get-Command to determine where the Out-ConsoleGridView cmdlet is from. (Easy if you want to use it on another system and are not sure from what module it originates from)

Check what Test cmdlets are available on the system

In the example below, I use Get-Command to return all the cmdlets starting with the Test Verb: (987 to be precise)

See what was imported in my current PowerShell session

In the example below, I use Get-Command to list all the imported commands: (433 to be precise)

Wrapping up

That’s the last blog post for 2024! 🙂 I covered how you can use Get-Command to search for and find information about everything available on your system; it’s just a nice way of discovering things!

Have a great New Year’s Eve, and I will see you next year!

Photo from last year in Amsterdam (Museumplein)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.