PowerShell Logo Small

Get-Command



This is the built-in help made by Microsoft for the command 'Get-Command', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

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}] [[-ArgumentLis
t] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]
Get-Command [-Noun <string[]>] [-Verb <string[]>] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParamet
ers>]



Search powershellhelp.space

DESCRIPTION


The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in the session, such as aliases, fu
nctions, 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 t
opic files.

Without parameters, "Get-Command" gets all of the cmdlets and functions in the current session. "Get-Command *" gets all Windows PowerShell eleme
nts and all of the non-Windows-PowerShell files in the Path environment variable ($env:path). It groups the files in the "Application" command ty
pe.

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 imp
orting a module.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113309
about_Command_Precedence
Get-Help
Get-PSDrive
Get-Member
Import-PSSession
Export-PSSession

REMARKS

<

Examples


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

C:\PS>get-command



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








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

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



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



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



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



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



Description
-----------
This command retrieves only parameters that are added to the Get-ChildItem cmdlet dynamically when it is used with the Windows PowerShell Certifi
cate 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-C
hildItem 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 cmdle
t 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 *



Description
-----------
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 whe
n 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 rem
ember 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 informati
on 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 sam
e 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 Nam
e 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.