Export (0) Print
Expand All

Get-Command

Updated: April 21, 2010

Applies To: Windows PowerShell 2.0

Gets commands in the current session.

Syntax

Get-Command [[-Name] <string[]>] [[-ArgumentList] <Object[]>] [-CommandType {<Alias> | <Function> | <Filter> | <Cmdlet> | <ExternalScript> | <Application> | <Script> | <All>}] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

Get-Command [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Noun <string[]>] [-Syntax] [-TotalCount <int>] [-Verb <string[]>] [<CommonParameters>]

Description

The Get-Command cmdlet gets commands in the session, such as aliases, functions, filters, scripts, and applications.

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

Without parameters, "Get-Command" gets all of the cmdlets, functions, and aliases in the current session. "Get-Command *" gets all types of commands that are available in the Windows PowerShell session, including all of the non-Windows-PowerShell files in the Path environment variable ($env:path), which it lists in the "Application" command type.

You can use the Module parameter of Get-Command to find the commands that were added to the session by a Windows PowerShell snap-in or module.

Parameters

-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 ArgumentList to a path in the provider drive, such as "WSMan:", "HKLM:" or "Cert:". When the command is a Windows PowerShell core 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.

 

Required?

false

Position?

2

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CommandType <CommandTypes>

Gets only the specified types of commands. Use "CommandType" or its alias, "Type". By default, Get-Command gets cmdlets, functions, and aliases.

Valid values are:

-- Alias: All Windows PowerShell aliases in the current session.

-- All: All command types. It is the equivalent of "get-command *".

-- Application: All non-Windows-PowerShell files in paths listed in the Path environment variable ($env:path), including .txt, .exe, and .dll files.

-- Cmdlet: The cmdlets in the current session. "Cmdlet" is the default.

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

-- Filter and Function: All Windows PowerShell functions.

-- Script: Script blocks in the current session.

 

Required?

false

Position?

named

Default Value

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 Get-Module, Get-PSSnapin, and Import-PSSession 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 or its output.

 

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 list commands with the same name in execution order, type the command name without wildcard characters. For more information, see the Notes section.

 

Required?

false

Position?

1

Default Value

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-Noun <string[]>

Gets cmdlets and functions with names that include the specified noun. <String> represents one or more nouns or noun patterns, such as "process" or "*item*". Wildcards are permitted.

 

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Syntax

Gets only specified data about the command.

* For aliases, retrieves the standard name.

* For cmdlets, retrieves the syntax.

* For functions and filters, retrieves the function definition.

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

 

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-TotalCount <int>

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

 

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Verb <string[]>

Gets information about cmdlets and functions with names that include the specified verb. <String> represents one or more verbs or verb patterns, such as "remove" or *et". Wildcards are permitted.

 

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This command supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters.

Inputs and Outputs

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

 

Inputs

System.String

You can pipe a "Name", "Command", and "Verb" noun-property specified, or a string object to Get-Command.

Outputs

System.Management.Automation.AliasInfo (for aliases), System.Management.Automation.ApplicationInfo (for applications and files), System.Management.Automation.FunctionInfo (for functions and filters), and System.Management.Automation.CmdletInfo (for cmdlets). All of these objects are derived from the System.Management.Automation.CommandInfo class.

The type of object that is returned depends on the type of command that Get-Command gets.

Notes

Get-Command returns the commands in alphabetical order. When the session contains more than one command with the same name, Get-Command returns the commands in execution order. The first command that is listed is the command that runs when you type the command name without qualification. For more information, see about_Command_Precedence.

Example 1

C:\PS>get-command

Description
-----------
This command gets the Windows PowerShell cmdlets, functions, and aliases in the current session.







Example 2

C:\PS>get-command -verb set | format-list *

Description
-----------
This command gets commands with the verb "set", and it displays all properties of the commands in a list.







Example 3

C:\PS>get-command -type cmdlet | sort-object noun | format-table -group noun

Description
-----------
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.







Example 4

C:\PS>get-command -module Microsoft.PowerShell.Security, TestModule

Description
-----------
This command gets the commands in the Microsoft.PowerShell.Security snap-in and the Test-Module module.







Example 5

C:\PS>get-command get-childitem -args cert: -syntax

Description
-----------
This command gets the syntax of the Get-ChildItem cmdlet when it is used in the Cert: drive. 

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.







Example 6

C:\PS>function Get-DynamicParameters
{
    param ($cmdlet, $psdrive)
    (get-command $cmdlet -ArgumentList $psdrive).parametersets | foreach-object {$_.parameters} | where-object { $_.IsDynamic } | select-object Name -unique
}

Get-DynamicParameters -cmdlet Get-ChildItem -psdrive cert:

Name
----
CodeSigningCert

Description
-----------
The function in this example gets the dynamic parameters that are added to a cmdlet when it is used in a specified drive. This is an alternative to the method used in the previous example.

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.







Example 7

C:\PS>get-command *

Description
-----------
This command gets all commands in the current session.

It also gets information about all of the 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).







Example 8

C:\PS>get-command | where-object {$_.definition -like "*first*"}

CommandType     Name                        Definition
-----------     ----                        ---------
Cmdlet          Select-Object               Select-Object [[-Property]

Description
-----------
This command finds a cmdlet or function based on the name of one of its parameters. You can use this command to identify a cmdlet or function when all that you can recall is the name of one of its parameters.

In this case, you recall that one of the cmdlets or functions has a First parameter that gets the first "n" objects in a list, but you cannot remember which cmdlet it is.

This command uses the Get-Command cmdlet to get a CmdletInfo object representing each of the cmdlets and functions in the session. The CmdletInfo object has a Definition property that contains the syntax of the cmdlet or function, which includes its parameters. 

The command uses a pipeline operator (|) to pass the CmdletInfo object to the Where-Object cmdlet, which examines the definition (syntax) of each object ($_) for a value that includes "first".

The result shows that the First parameter belongs to the Select-Object cmdlet.







Example 9

C:\PS>get-command dir | format-list

Name              : dir
CommandType       : Alias
Definition        : Get-ChildItem
ReferencedCommand : Get-ChildItem
ResolvedCommand   : Get-ChildItem

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

This command displays the "dir" alias in the current console. The command pipes the result to the Format-List cmdlets.







Example 10

C:\PS>get-command notepad

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

Description
-----------
This example shows how to use Get-Command to determine which command Windows PowerShell runs when the session contains multiple commands with the same name. When you use the Name parameter without wildcard characters, Get-Command lists the commands with that name in execution precedence order.

This command shows which Notepad program Windows PowerShell runs when you type "Notepad" without a fully qualified path. The command uses the Name parameter without wildcard characters. 

The sample output shows the Notepad commands in the current console. It indicates that Windows PowerShell will run the instance of Notepad.exe in the C:\Windows\System32 directory.







Example 11

C:\PS>(get-command get-date).pssnapin

C:\PS> (get-command remove-gpo).module

Description
-----------
These commands show how to find the snap-in or module from which a particular cmdlet originated.

The first command uses the PSSnapin property of the CmdletInfo object to find the snap-in that added the Get-Date cmdlet. 

The second command uses the Module property of the CmdletInfo object to find the module that added the Remove-GPO cmdlet.







Example 12

C:\PS>get-command -type cmdlet | where-object {$_.outputtype} | format-list -property name, outputtype

Description
-----------
This command gets the cmdlets in the session and the .NET type of the objects that they return. 

The first part of the command gets the cmdlets in the session. A pipeline operator (|) sends the cmdlet objects 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 Get-Command has a non-null value only when the cmdlet code defines the OutputType attribute for the cmdlet.







See Also

Community Additions

Show:
© 2014 Microsoft