powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Get-Command



NAME
Get-Command

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

SYNTAX
Get-Command [[-Name] ] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application |
Script | All}] [[-ArgumentList] ] [-Module ] [-Syntax] [-TotalCount ] [
]

Get-Command [-Noun ] [-Verb ] [[-ArgumentList] ] [-Module ] [-Syntax] [-Tot
alCount ] []


DESCRIPTION
The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in th
e 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 ge
ts its information from help topic files.

Without parameters, "Get-Command" gets all of the cmdlets and functions in the current session. "Get-Command *" get
s all Windows PowerShell elements and all of the non-Windows-PowerShell files in the Path environment variable ($en
v: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 Win
dows PowerShell snap-in or importing a module.


PARAMETERS
-ArgumentList
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 Ar
gumentList to a path in the provider drive, such as "HKML\Software" or "cert:\my".

Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false

-CommandType
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
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-Module
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 cho
ose 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
Gets information only about the cmdlets or command elements with the specified name. 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
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-Noun
Gets cmdlets and functions with names that include the specified noun. 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 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
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-TotalCount
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
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-Verb
Gets information about cmdlets and functions with names that include the specified verb. represents on
e 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


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

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 cmd
let 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 informa
tion 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 th
e same name, Get-Command returns the commands in execution order. The first command that is listed is the comm
and that runs when you type the command name without qualification. For more information, see about_Command_Pre
cedence.


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





-------------------------- 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 t
hat 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 displ
ays 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 Power
Shell Certificate provider.

When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (Argum
entList) 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 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 fr
om 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 para
meters 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 *


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 retur
ns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo object (S
ystem.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 ide
ntify 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 t
he 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-C
ommand 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 cmdle
ts.





-------------------------- 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 list
s 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 c
mdlet.

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






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