Search notes:

PowerShell cmdLet Get-Command

The get-command cmdLet returns an array of objects that are derived from System.Management.Automation.CommandInfo. These objects can then be queried about the individual commands.

get-command

get-command returns all installed commands.

get-command *

get-command * additionally includes EXEs that are in the PATH environment variable ($env:path).
get-command *-command lists all commands whose noun is command:
PS:\> get-command *-command
CommandType     Name               Version    Source
-----------     ----               -------    ------
Function        Find-Command       1.0.0.1    PowerShellGet
Cmdlet          Get-Command        3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Invoke-Command     3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Measure-Command    3.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Show-Command       3.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Trace-Command      3.1.0.0    Microsoft.PowerShell.Utility

Show a parameter summary for functions or cmdLets (-syntax)

The -syntax switch allows to quickly get an overview of a cmdLet's or function's parameters, their types and if they're optional or mandatory
PS Users\Rene> get-command get-process -syntax

Get-Process [[-Name] <string[]>] [-ComputerName <string[]>] [-Module] [-FileVersionInfo] [<CommonParameters>]

Get-Process [[-Name] <string[]>] -IncludeUserName [<CommonParameters>]

Get-Process -Id <int[]> -IncludeUserName [<CommonParameters>]

Get-Process -Id <int[]> [-ComputerName <string[]>] [-Module] [-FileVersionInfo] [<CommonParameters>]

Get-Process -InputObject <Process[]> -IncludeUserName [<CommonParameters>]

Get-Process -InputObject <Process[]> [-ComputerName <string[]>] [-Module] [-FileVersionInfo] [<CommonParameters>]

Show body of a function

The body (or definition) of a PowerShell: function statement can be shown like so
(get-command mkdir).definition

Querying meta info about a command

The System.Management.Automation.CommandInfo object that get-object returns can be passed to the constructor of System.Management.Automation.CommandMetadata. The object that this constructor creates can then be used to query some meta data about a command.
In the following example, this technique is rudimentarily covered with an alias and a cmdLet:
#
#  Get the two CommandInfo objects:
#
PS C:\> $lsCommand          = get-command ls
PS C:\> $stopProcessCommand = get-command stop-process

#
#  Get the object's respective CommandMetadata objects:
#
PS C:\> $lsMeta          = new-object System.Management.Automation.CommandMetadata($lsCommand)
PS C:\> $stopProcessMeta = new-object System.Management.Automation.CommandMetadata($stopProcessCommand)

#
# ls is an alias for get-childItem:
#
PS C:\> $lsMeta.Name
Get-ChildItem

#
# Show a cmdLet's help URI
#
PS C:\> $stopProcessMeta.HelpUri
https://go.microsoft.com/fwlink/?LinkID=113412
See also Let PowerShell describe a function's parameters

Getting all commands with a given parameter name

The following command lists all commands with the -asJob parameter name:
get-command -parameterName asJob

Check if a given command or executable is present

The following command uses get-command to check if an executable (here: the C# compiler) is present and prints yes if so, no otherwise.
if ($null = get-command -errorAction ignore csc)  {'yes'} else {'no'}
The same construct can also be used to check the existence of a PowerShell script.

See also

The Windows executable where.exe and the Shell command which.
Powershell command noun: command

Index