Share this post:This blog post is part of an ongoing series by Adam Gordon. Adam will walk through each PowerShell command every week, explaining when and how to use them. Adam will be covering Get-Command this week.
When should you use Get-Command
The Get-Command cmdlet retrieves all commands installed on the computer. This includes cmdlets, aliases and functions, filters, scripts and scripts. Get-Command retrieves commands from PowerShell modules as well as commands that were imported from another session. Use the -ListImported parameter to only retrieve commands that have been imported into your current session.
Get-Command * lists all types of commands, even those that are not PowerShell files.
Get-Command, which requires the exact name of your command without wildcard characters to import the module containing the command automatically. This allows you to use the command immediately. To enable, disable, and configure automatic importing of modules, you can use the $PSModuleAutoLoadingPreference preference variable.
NOTE: Get-Command receives its data directly from the command line, unlike Get-Help which gets its information via help topics.
Windows PowerShell5.0 now displays a Version column as a default result of the Get-Command cmdlet. The CommandInfo class now has a new Version property.
What version of PowerShell should I use for this blog?
Get the PowerShell Version for your machine
This command displays the PowerShell version information for your machine.
How to use Get-Command
Get cmdlets, functions and aliases
This command installs the PowerShell cmdlets and functions on the computer.
Take commands during the current session
This command uses -ListImported to only get commands from the current session.
Display cmdlets in the order you want.
Sort-Object -Property Noun
This command retrieves all cmdlets and sorts them alphabetically according to the noun in their names. Then, it displays them in noun-based groupings.
You can get commands in a module
Get-Command -Module Microsoft.PowerShell.Security, Microsoft.PowerShell.Utility
This command uses the -Module parameter to get the commands in the Microsoft.PowerShell.Security and Microsoft.PowerShell.Utility modules.
Find out more about a cmdlet
This command provides information about the Get AppLockerPolicy cmdlet. It also imports AppLocker module. This adds all commands from the AppLocker modules to the current session.
Find the syntax for a cmdlet
Get-Command Get-Childitem -Args Cert: -Syntax
This command uses the –ArgumentList, –Syntax parameters in order to obtain the syntax of Get-ChildItem cmdlet if it is used in Cert: drive. The Cert drive is a PowerShell drive that Certificate Provider adds into the session.
Compare the syntax in the output with the syntax when you omit -Args (ArgumentList parameter), and you’ll see that the Certificate provider adds CodeSigningCert dynamic parameter to the Get-ChildItem cmdlet.
Get dynamic parameters:
function Get-DynamicParameters ForEach-Object $_.Parameters Get-DynamicParameters -Cmdlet Get-ChildItem -PSDrive Cert:
The command in the example uses the Get-DynamicParameters function to get the dynamic parameters that the Certificate provider adds to the Get-ChildItem cmdlet when it is used in the Cert: drive.
The Get-DynamicParameters function in this example gets the dynamic parameters of a cmdlet. This alternative method is to the one used in the previous example. A provider or another cmdlet can add dynamic parameter to a cmdlet.
Use a parameter type and name to get cmdlets
Get-Command -ParameterName *Auth* -ParameterType AuthenticationMechanism
This command gets cmdlets that have a parameter whose name includes Auth and whose type is AuthenticationMechanism.
The -ParameterType parameter distinguishes parameters that take an AuthenticationMechanism value from those that take an -AuthenticationLevel parameter, even when they have similar names.
You can get cmdlets and functions with an output type:
This command returns the cmdlets or functions that have an output type as well as the type of objects they return.
All cmdlets are available in the first part of the command. ) sends the cmdlets to the Where-Object cmdlet, which selects only the ones in which the OutputType property is populated.
Another pipeline operator sends selected cmdlet objects back to the