Create a Function/Cmdlet Alias using the [Alias()] attribute

2016/05/08 | less than 1 minute read |

Just wanted to share a small PowerShell tips that Kirk Munro found. You can declare a function or Cmdlet Alias using the following keyword [Alias("MyAlias")]

Example:

function Get-This
{
    [CmdletBinding()]
    [Alias("Get-That")]
    PARAM (
        $Param1
    )
    
    Write-Output "Param1 = $param1"
}

Get-That -Param1 "Hello World"

According to Jason Shirk this has been added in PowerShell v4.0: “Support for the alias attribute on a function or cmdlet (works in C# too!) was added in V4. It’s most valuable in a binary module because it’s harder to create aliases via IModuleAssemblyInitializer and when you do via that interface

Function Alias

Leave a Comment