liveBook · Manning

Alias

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

A parameter alias is an alternate name accepted by a command for one of its parameters.

A parameter alias is an alternate name accepted by a command for one of its parameters. It lets a familiar or shorter name select the same parameter without changing the command’s behavior. section 4.6.2

For example, Get-Process has an -ErrorAction parameter whose alias is -ea. Both names select the same common parameter, although the standard help display does not show -ea. section 4.6.2

Discover and use a parameter alias with these practical steps:

  • Inspect the command’s parameter metadata to find aliases: (Get-Command Get-Process | Select-Object -Expand Parameters).ErrorAction.Aliases. section 4.6.2
  • Use the discovered alias in a command, such as Get-Process -ea Stop. section 4.6.2
  • Remember that tab completion can reveal an alias even when command help does not explain its relationship to the full parameter name. section 4.6.2

When defining a script parameter, add an Alias attribute. A disk-inventory script can accept -host as an alternative name for -ComputerName while retaining the conventional full parameter name. section 20.4

Adding a script parameter alias

Declare the parameter as [Alias('host')][string]$computername, then run the script with .\Get-DiskInventory -host SRV02. The alias belongs to -ComputerName, not to another parameter such as -drivetype. section 20.4 section 20.7

PS /Users/james> (get-command get-process | select -Expand 
 parameters).erroraction.aliases

Inspect a command’s parameter metadata to locate the aliases attached to a specific parameter. section 4.6.2

Choose aliases that clarify a script without creating ambiguity. The example avoids -hostname because that name indicates an SSH connection in PowerShell remoting, and parameter aliases can be difficult for other users to discover. section 20.4 section 4.6.2

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains discovery, invocation, tab completion, and script declaration, but stops short of broader parameter-binding internals.
Examples
Uses Get-Process -ea Stop and a Get-DiskInventory script accepting -host for -ComputerName.
What it assumes
Assumes familiarity with PowerShell commands and parameters while teaching alias discovery and declaration directly.
What you can do after
Build it from scratch by declaring an Alias attribute and diagnose existing aliases through command parameter metadata.
How it connects
Connects parameter aliases with common parameters, tab completion, command metadata, script parameters, and PowerShell remoting.

Also explained in

Compare how 6 books explain alias →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.