How to use an alias() for the parameter in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

PowerShell alias is a good way to use the shortcut name for the Parameter instead of writing the full name of the parameter. For example, you can refer to Server as ServerName, AppID as the ApplicationID.

So you don’t have to use the whole name of the parameter and it is easy to remember as well.

Example

function Aliastest{
   param(
      [parameter(Mandatory=$true)]
      [Alias("Server")]
      [string]$ServerName
   )
   Write-Output "Server name is $ServerName"
}

Now we can use the Server instead of ServerName while passing the arguments.

PS C:\> Aliastest -server "Test1-Win2k16"
Server name is Test1-Win2k16
raja
Published on 09-Nov-2020 09:33:03
Advertisements