Self Aliased Functions in PowerShell

Just a tip #12

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
        [string] $Name
    Write-Host "Hello, $Name!"

Share it on     |   |   |   | 

Magic of $MyInvocation in PowerShell


Find Azure Resources By Tags Using PowerShell

comments powered by Disqus