Gets basic information about cmdlets and other elements of Windows PowerShell commands.

Syntax

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

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

Description

The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in the session, such as aliases, functions, filters, scripts, and applications.

Get-Command gets its data directly from the code of a cmdlet, function, script, or alias, unlike Get-Help, which gets its information from help topic files.

Without parameters, "Get-Command" gets all of the cmdlets and functions in the current session. "Get-Command *" gets all Windows PowerShell elements and all of the non-Windows-PowerShell files in the Path environment variable ($env:path). It groups the files 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 adding a Windows PowerShell snap-in or importing a module.

Parameters

-ArgumentList <Object[]>

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

To detect parameters that are added to a cmdlet when it is used with a particular provider, set the value of ArgumentList to a path in the provider drive, such as "HKML\Software" or "cert:\my".

Required?

false

Position?

2

Default Value

none

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 and functions.

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

none

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.

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.

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

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Name <string[]>

Gets information only about the cmdlets or command elements with the specified name. <String> represents all or part of the name of the cmdlet or command element. 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

none

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

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Syntax

Gets only specified data about the command element.

* 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

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-TotalCount <int>

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

Required?

false

Position?

named

Default Value

none

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

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. 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

Object

The type of object returned depends on the type of command element retrieved. For example, Get-Command on a cmdlet retrieves a CmdletInfo object, while Get-Command on a DLL retrieves an ApplicationInfo object.

Notes

Without parameters, "Get-Command" gets information about the Windows PowerShell cmdlets and functions. Use the parameters to qualify the elements retrieved.

Unlike Get-Help, which displays the contents of XML-based help topic files, Get-Command gets its cmdlet information directly from the cmdlet code in the system.

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

This command gets information about all of the Windows PowerShell cmdlets and functions. 

The default display lists the command type ("Cmdlet" or "Function" or "Filter"), the name of the cmdlet or function, and the syntax or function definition.






Example 2

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

This command gets information about all of the cmdlets and functions with the verb "set", and it displays some of that information in a list. 

The list format includes fields that are omitted from the table display, including the complete syntax. To display all fields (all properties of the object), type "get-command -verb set | format-list *".






Example 3

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

This command retrieves 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. 

By default, Get-Command displays items in the order in which the system discovers them, which is also the order in which they are selected to run when a run command is ambiguous.






Example 4

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

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

The Module parameter gets commands that were added by importing modules or adding Windows PowerShell snap-ins.






Example 5

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

This command retrieves information about the Get-ChildItem cmdlet when Get-ChildItem is used with the Windows PowerShell Certificate provider. 

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 dynamically adds a parameter, CodeSigningCert, to the Get-ChildItem cmdlet.






Example 6

C:\PS>(get-command get-childitem -ArgumentList cert:).parametersets[0].parameters | where-object { $_.IsDynamic }

This command retrieves only parameters that are added to the Get-ChildItem cmdlet dynamically when it is used with the Windows PowerShell Certificate provider. This is an alternative to the method used in the previous example.

In this command, the "get-command get-childitem -ArgumentList cert:" is processed first. It requests information from Get-Command about the Get-ChildItem cmdlet when it is used with the Certificate provider. The ".parametersets[0]" selects the first parameter set (set 0) of "get-childitem -argumentList cert:" and ".parameters" selects the parameters in that parameter set. The resulting parameters are piped to the Where-Object cmdlet to test each parameter ("$_.") by using the IsDynamic property. To find the properties of the objects in a command, use Get-Member.






Example 7

C:\PS>get-command *

This command gets information about the Windows PowerShell cmdlets, functions, filters, scripts, and aliases in the current console.

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 displays information about the code in 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 it has access to 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.






See Also




Table Of Contents