Monthly Archive

Categories

PowerShell commands

When you think of PowerShell commands most people think of cmdlets but that’s not the full story.

PowerShell commands encompass:

Aliases

Functions

Cmdlets

Native Windows commands

When you type a command name the command types listed above are checked in order to determine the command to run – specifically aliases, then functions, then cmdlets and finally native commands.

 

If you want to se this in action try

PS> function get-date {get-process}
PS> get-date

And you’ll get a list of processes!

 

Get-command by default will only show the function! To see all commands

PS> Get-Command get-date -All

CommandType Name
----------- ----
Function get-date
Cmdlet Get-Date

 

You can still execute the cmdlet version:

PS> & (Get-Command get-date -All)[1]

25 June 2018 14:53:43

or

PS> & (Get-Command get-date -CommandType cmdlet)

by using the call operator & on the cmdlet

or alternatively you can use the module name to qualify the command

PS> Microsoft.PowerShell.Utility\get-date

25 June 2018 14:54:16

Comments are closed.