Precedence
When entering a command in a PowerShell session, the following order of precedence is applied to resolve the command if multiple commands have the same name:
An example of an ambigous command on Windows, PowerShell 5.1, is
sc
which can refer either to the executable
sc.exe
or the alias for
set-content
) (Apparently, in PowerShell 7,
sc
is not pre-defined as alias anymore):
get-command sc -all
CommandType Name Version Source
----------- ---- ------- ------
Alias sc -> Set-Content
Application sc.exe 10.0.19... C:\WINDOWS\system32\sc.exe
In order to make sure that a specific command type is executed, the
PowerShell: call operator (&)[call operator (
&
) might be used on an object that is returned by
get-command … -commandType …
:
& (get-command sc -commandType application) query
If a command cannot be resolved, PowerShell also tries to resolve it by prepending it with
get-
. For example: entering
job
executes
get-job
.
See also
Commands that are entered on the prompt (CLI) are stored in the
command history
The
automatic variable
myInvocation
stores information about the current command
if the command is a script, a function or a script block.