When we are working with an interactive shell, we use aliases for the frequently used cmdlets, and aliases are really useful and reduce the amount of keystrokes, and very simple and easy to use, and sometimes they can do magics as well.
It is not recommended to use the aliases in the scripts and functions as part of the best practices.
We can create aliases to cmdlets and functions, end even to scripts using the New-Alias
cmdlet…
New-Alias -Name hello -Value Hello-Word
And, we can also create aliases to the function at the time of declaration itself using [Alias("")]
statement, we need to place it just before the parameters block param
.
Parameters block is mandatory, at least an empty block
param()
Function Hello-World
{
[Alias('hello','hey')]
param
(
[string] $Name
)
Write-Host "Hello, $Name!"
}