Export (0) Print
Expand All

Get-Command

Published: February 29, 2012

Updated: August 15, 2012

Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0

Get-Command

Gets all commands.

Aliases

The following abbreviations are aliases for this cmdlet:

  • gcm

Syntax

Parameter Set: CmdletSet
Get-Command [[-ArgumentList] <Object[]> ] [-All] [-ListImported] [-Module <String[]> ] [-Noun <String[]> ] [-ParameterName <String[]> ] [-ParameterType <PSTypeName[]> ] [-Syntax] [-TotalCount <Int32> ] [-Verb <String[]> ] [ <CommonParameters>]

Parameter Set: AllCommandSet
Get-Command [[-Name] <String[]> ] [[-ArgumentList] <Object[]> ] [-All] [-CommandType <CommandTypes> ] [-ListImported] [-Module <String[]> ] [-ParameterName <String[]> ] [-ParameterType <PSTypeName[]> ] [-Syntax] [-TotalCount <Int32> ] [ <CommonParameters>]




Detailed Description

The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, workflows, filters, scripts, and applications. Get-Command gets the commands from Windows PowerShell modules and snap-ins 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, a "Get-Command" command gets all of the cmdlets, functions, workflows and aliases installed on the computer. A "Get-Command *" command gets all types of commands, including all of the non-Windows-PowerShell files in the Path environment variable ($env:path), which it lists in the "Application" command type.

A Get-Command command that uses the exact name of the command (without wildcard characters) automatically imports the module that contains the command so 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 (http://go.microsoft.com/fwlink/?LinkID=113248).

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

In Windows PowerShell 2.0, Get-Command gets only commands in current session. It does not get commands from modules that are installed, but not imported. To limit Get-Command in Windows PowerShell 3.0 and later to commands in the current session, use the ListImported parameter.

Parameters

-All

Gets all commands, including commands of the same type that have the same name. By default, Get-Command gets only the commands that run when you type the command name.

For more information about the method that Windows PowerShell uses to select the command to run when multiple commands have the same name, see about_Command_Precedence (http://go.microsoft.com/fwlink/?LinkID=113214). For information about module-qualified command names and running commands that do not run by default because of a name conflict, see about_Modules (http://go.microsoft.com/fwlink/?LinkID=144311).

This parameter is introduced in Windows PowerShell 3.0.

In Windows PowerShell 2.0, Get-Command gets all commands by default.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ArgumentList<Object[]>

Gets information about a cmdlet or function when it is used with the specified parameters ("arguments"). The alias for ArgumentList is Args.

To detect dynamic parameters that are available only when certain other parameters are used, set the value of ArgumentList to the parameters that trigger the dynamic parameters.

To detect the dynamic parameters that a provider adds to a cmdlet, set the value of the ArgumentList parameter to a path in the provider drive, such as "WSMan:", "HKLM:" or "Cert:". When the command is a Windows PowerShell provider cmdlet, enter only one path in each command; the provider cmdlets return only the dynamic parameters for the first path the value of ArgumentList. For information about the provider cmdlets, see about_Providers (http://go.microsoft.com/fwlink/?LinkID=113250).


Aliases

Args

Required?

false

Position?

2

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CommandType<CommandTypes>

Gets only the specified types of commands. Enter one or more command types. Use CommandType or its alias, Type. By default, Get-Command gets all cmdlets, functions, and workflows, and aliases.

Valid values are:

-- Alias: Gets the aliases of all Windows PowerShell commands. For more information, see about_Aliases.

-- All: Gets all command types. This parameter value is the equivalent of "Get-Command *".

-- Application: Gets non-Windows-PowerShell files in paths listed in the Path environment variable ($env:path), including .txt, .exe, and .dll files. For more information about the Path environment variable, see about_Environment_Variables.

-- Cmdlet: Gets all cmdlets.

-- ExternalScript: Gets all .ps1 files in the paths listed in the Path environment variable ($env:path).

-- Filter and Function: Gets all Windows PowerShell advanced and simple functions and filters.

-- Script: Gets all script blocks. To get Windows PowerShell scripts (.ps1 files), use the ExternalScript value.

-- Workflow: Gets all workflows. For more information about workflows, see Introducing Windows PowerShell Workflow.


Aliases

Type

Required?

false

Position?

named

Default Value

Cmdlets, functions, workflows, and alias

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Module<String[]>

Gets the commands that came from the specified modules or snap-ins. Enter the names of modules or snap-ins, or enter snap-in or module objects.

This parameter takes string values, but the value of this parameter can also be a PSModuleInfo or PSSnapinInfo object, such as the objects that the Get-Module, Get-PSSnapin, and Import-PSSession cmdlets return.

You can refer to this parameter by its name, Module, or by its alias, PSSnapin. The parameter name that you choose has no effect on the command output.


Aliases

PSSnapin

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Name<String[]>

Gets only commands with the specified name. Enter a name or name pattern. Wildcards are permitted.

To get commands that have the same name, use the All parameter. When two commands have the same name, by default, Get-Command gets the command that runs when you type the command name.


Aliases

none

Required?

false

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-Noun<String[]>

Gets commands (cmdlets, functions, workflows, and aliases) that have names that include the specified noun. Enter one or more nouns or noun patterns. Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

All nouns

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Syntax

Gets only specified data about the command.

* For aliases, gets the standard name.

* For cmdlets, gets the syntax.

* For functions and filters, gets the function definition.

* For scripts and applications (files), gets the path and filename.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-TotalCount<Int32>

Gets the specified number of commands. You can use this parameter to limit the output of a command.


Aliases

none

Required?

false

Position?

named

Default Value

All commands

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Verb<String[]>

Gets commands (cmdlets, functions, workflows, and aliases) that have names that include the specified verb. Enter one or more verbs or verb patterns. Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

All verbs

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ListImported

Gets only commands in the current session.

Beginning in Windows PowerShell 3.0, by default, Get-Command gets all installed commands, including, but not limited to, the commands in the current session. In Windows PowerShell 2.0, it gets only commands in the current session.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ParameterName<String[]>

Gets commands in the session that have the specified parameters. Enter parameter names and/or parameter aliases. Wildcard are supported.

The ParameterName and ParameterType parameters search only commands in the current session.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

All parameter names

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ParameterType<PSTypeName[]>

Gets commands in the session that have parameters of the specified type. Enter the full name or partial name of a parameter type. Wildcards are supported.

The ParameterName and ParameterType parameters search only commands in the current session.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

All parameter types

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.String

    You can pipe command names to Get-Command.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.Management.Automation.CommandInfo

    All Get-Command output types are derived from this class. The type of object that is returned depends on the type of command that Get-Command gets.


  • System.Management.Automation.AliasInfo

    Represents aliases.


  • System.Management.Automation.ApplicationInfo

    Represents or applications and files


  • System.Management.Automation.CmdletInfo

    Represents cmdlets.


  • System.Management.Automation.FunctionInfo

    Represents functions and filters


  • System.Management.Automation.WorkflowInfo

Notes

  • When more than one command with the same name is available to the session, Get-Command returns the command that runs when you type the command name. To get commands with the same name (listed in execution order), use the All parameter. For more information, see about_Command_Precedence.

  • When a module is imported automatically, the effect is the same as using the Import-Module cmdlet. The module can add commands, types and formatting files, and run scripts in the session. To enable, disable, and configuration automatic importing of modules, use the $PSModuleAutoLoadingPreference preference variable. For more information, see about_Preference_Variables (http://go.microsoft.com/fwlink/?LinkID=113248).

Examples

-------------------------- EXAMPLE 1 --------------------------

This command gets the Windows PowerShell cmdlets, functions, and aliases that are installed on the computer.


PS C:\> Get-Command

-------------------------- EXAMPLE 2 --------------------------

This command uses the ListImported parameter to get only the commands in the current session.


PS C:\> Get-Command -ListImported

-------------------------- EXAMPLE 3 --------------------------

This command gets all of the cmdlets, sorts them alphabetically by the noun in the cmdlet name, and then displays them in noun-based groups. This display can help you find the cmdlets for a task.


PS C:\> Get-Command -Type Cmdlet | Sort-Object -Property Noun | Format-Table -GroupBy Noun

-------------------------- EXAMPLE 4 --------------------------

This command uses the Module parameter to get the commands in the Microsoft.PowerShell.Security and PSScheduledJob modules.


PS C:\> Get-Command -Module Microsoft.PowerShell.Security, PSScheduledJob

-------------------------- EXAMPLE 5 --------------------------

This command gets information about the Get-AppLockerPolicy cmdlet. It also imports the AppLocker module, which adds all of the commands in the AppLocker module to the current session.

When a module is imported automatically, the effect is the same as using the Import-Module cmdlet. The module can add commands, types and formatting files, and run scripts in the session. To enable, disable, and configuration automatic importing of modules, use the $PSModuleAutoLoadingPreference preference variable. For more information, see about_Preference_Variables (http://go.microsoft.com/fwlink/?LinkID=113248).


PS C:\> Get-Command Get-AppLockerPolicy

-------------------------- EXAMPLE 6 --------------------------

This command uses the ArgumentList and Syntax parameters to get the syntax of the Get-ChildItem cmdlet when it is used in the Cert: drive. The Cert: drive is a Windows PowerShell drive that the Certificate Provider adds to the session.

When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (ArgumentList) parameter, you'll see that the Certificate provider adds a dynamic parameter, CodeSigningCert, to the Get-ChildItem cmdlet.

For more information about the Certificate provider, see Certificate Provider.


PS C:\> Get-Command Get-Childitem -Args Cert: -Syntax

-------------------------- EXAMPLE 7 --------------------------

The Get-DynamicParameters function in this example gets the dynamic parameters of a cmdlet. This is an alternative to the method used in the previous example. Dynamic parameter can be added to a cmdlet by another cmdlet or a provider.

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.


PS C:\> function Get-DynamicParameters
{
    param ($Cmdlet, $PSDrive)
    (Get-Command $Cmdlet -ArgumentList $PSDrive).ParameterSets | ForEach-Object {$_.Parameters} | Where-Object { $_.IsDynamic } | Select-Object -Property Name -Unique
}
PS C:\> Get-DynamicParameters -Cmdlet Get-ChildItem -PSDrive Cert:

Name
----
CodeSigningCert

-------------------------- EXAMPLE 8 --------------------------

This command gets all commands of all types on the local computer, including executable files in the paths of the Path environment variable ($env:path). It returns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo object (System.IO.FileInfo).


PS C:\> Get-Command *

-------------------------- EXAMPLE 9 --------------------------

This command gets cmdlets that have a parameter whose name includes "Auth" and whose type is AuthenticationMechanism. You can use a command like this one to find cmdlets that let you specify the method that is used to authenticate the user.

The ParameterType parameter distinguishes parameters that take an AuthenticationMechanism value from those that take an AuthenticationLevel parameter, even when they have similar names.


PS C:\> Get-Command -ParameterName *Auth* -ParameterType AuthenticationMechanism

-------------------------- EXAMPLE 10 --------------------------

This example shows how to use the Get-Command cmdlet with an alias. Although it is typically used on cmdlets and functions, Get-Command also gets scripts, functions, aliases, workflows, and executable files.

The output of the command shows the special view of the Name property value for aliases. The view shows the alias and the full command name.


PS C:\> Get-Command dir
CommandType     Name                                               ModuleName
----------- ---- ----------
Alias dir -> Get-ChildItem

-------------------------- EXAMPLE 11 --------------------------

This example uses the All parameter of the Get-Command cmdlet to show all instances of the "Notepad" command on the local computer. The All parameter is useful when there is more than one command with the same name in the session.

Beginning in Windows PowerShell 3.0, by default, when the session includes multiple commands with the same name, Get-Command gets only the command that runs when you type the command name. With the All parameter, Get-Command gets all commands with the specified name and returns them in execution precedence order. To run a command other than the first one in the list, type the fully qualified path to the command.

For more information about command precedence, see about_Command_Precedence (http://go.microsoft.com/fwlink/?LinkID=113214).


PS C:\> Get-Command Notepad -All | Format-Table CommandType, Name, Definition

CommandType     Name           Definition
-----------     ----           ----------
Application     notepad.exe    C:\WINDOWS\system32\notepad.exe
Application     NOTEPAD.EXE    C:\WINDOWS\NOTEPAD.EXE

-------------------------- EXAMPLE 12 --------------------------

This command gets the name of the snap-in or module in which the Get-Date cmdlet originated. The command uses the ModuleName property of all commands.

This command format works on commands in Windows PowerShell modules and snap-ins, even if they are not imported into the session.


PS C:\> (Get-Command Get-Date).ModuleName
Microsoft.PowerShell.Utility

-------------------------- EXAMPLE 13 --------------------------

This command gets the cmdlets and functions that have an output type and the type of objects that they return.

The first part of the command gets all cmdlets. A pipeline operator (|) sends the cmdlets to the Where-Object cmdlet, which selects only the ones in which the OutputType property is populated. Another pipeline operator sends the selected cmdlet objects to the Format-List cmdlet, which displays the name and output type of each cmdlet in a list.

The OutputType property of a CommandInfo object has a non-null value only when the cmdlet code defines the OutputType attribute for the cmdlet.


PS C:\> Get-Command -Type Cmdlet | Where-Object OutputType | Format-List -Property Name, OutputType

-------------------------- EXAMPLE 14 --------------------------

This command finds cmdlets that take net adapter objects as input. You can use this command format to find the cmdlets that accept the type of objects that any command returns.

The command uses the PSTypeNames intrinsic property of all objects, which gets the types that describe the object. To get the PSTypeNames property of a net adapter, and not the PSTypeNames property of a collection of net adapters, the command uses array notation to get the first net adapter that the cmdlet returns.


PS C:\> Get-Command -ParameterType (((Get-NetAdapter)[0]).PSTypeNames)
CommandType     Name                                               ModuleName
----------- ---- ----------
Function Disable-NetAdapter NetAdapter
Function Enable-NetAdapter NetAdapter
Function Rename-NetAdapter NetAdapter
Function Restart-NetAdapter NetAdapter
Function Set-NetAdapter NetAdapter

Related topics


Export-PSSession

Get-Help

Get-Member

Get-PSDrive

Import-PSSession

about_Command_Precedence



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft