The Alias attribute
Like CmdletBinding
, the Alias
attribute may be placed before the param
block. It may be used before or after CmdletBinding
; the ordering of attributes does not matter.
The Alias
attribute is used to optionally create aliases for a function. A function can have one or more aliases; the attribute accepts either a single value or an array of values. For example, an alias gsm
can be added to the Get-Something
function by adding the Alias
attribute:
function Get-Something {
[CmdletBinding()]
[Alias('gsm')]
param ( )
Write-Host 'Running Get-Something'
}
The alias is immediately available if the function is pasted into the console:
PS> gsm
Running Get-Something
The Get-Alias
command will also show the alias has been created:
PS> Get-Alias gsm
CommandType Name Version Source
----------- ---- ------- ------
Alias gsm -> Get-Something
The...