PowerShell Aliases: Save Time But Use Wisely

When typing interactive PowerShell commands, some cmdlets can be lengthy. Save yourself some time by making use of a PowerShell cmdlet’s Alias.

PowerShell is designed for readability

A big PowerShell strength is its readability. Cmdlets follow a standard Verb-Noun format and avoid any acronyms that aren’t considered common knowledge. By simply looking at a command, you can quickly understand what it is intended to do.

Readability is very important when you are creating a finished script that will be reviewed, used, and updated by others. But what about when you are simply performing some interactive work from a PowerShell prompt? You can tab autocomplete a cmdlet, but that still requires a minimum amount of typing and you may need to tab through a few cmdlets before you get to the one you want. Save yourself some time and typing by using a cmdlet’s Alias.

PowerShell

1

2

3

4

5

6

7

8

PSC:\Users\aaron>Get-Service-DisplayName'Windows Update'

Status Name DisplayName

---------------------

Stopped wuauserv Windows Update

What’s a PowerShell Alias?

PowerShell Aliases are shortcuts or shortcode for a PowerShell cmdlet. Instead of typing an entire cmdlet name, you can type a predetermined combination of letters that PowerShell will correctly translate to the given cmdlet.

For example, instead of typing Get-Service, I can type gsv:

PowerShell

1

2

3

4

5

6

7

8

PSC:\Users\aaron>gsv-DisplayName'Windows Update'

Status Name DisplayName

---------------------

Stopped wuauserv Windows Update

And that is pretty much all there is to an Alias. PowerShell comes with a bunch of built-in Aliases, which you can see with the cmdlet Get-Alias. If you don’t use any parameters, it will list all of the Aliases available on the computer.

If you want to see if there is an Alias for a specific cmdlet, you can use the -Definition parameter along with the name of the cmdlet (below). Note that there can be more than one Alias for a cmdlet, but never more than one cmdlet tied to an Alias.

PowerShell

1

2

3

4

5

6

7

8

9

PSC:\Users\aaron>Get-Alias-DefinitionGet-Process

CommandType Name Version Source

----------------------------

Alias gps->Get-Process

Alias ps->Get-Process

Create a custom PowerShell Alias

Let’s say you drop into a PowerShell prompt and are getting ready to type the same cmdlet a bunch of times (NOTE: This shouldn’t really ever be a scenario; use piping, loops or a script!). Unfortunately, you find out there is no built-in Alias for the cmdlet (below).

PowerShell

1

2

3

4

5

6

7

8

9

10

PSC:\Users\aaron>Get-Alias-DefinitionGet-ControlPanelItem

Get-Alias:This command cannot findamatching alias because an alias with the definition'Get-ControlPanelItem'does not exist.

If you want to have this Alias persist for your user on the computer your using after your PowerShell session ends, you can add the Set-Alias command to your PowerShell profile (which is a topic for another day).

Built-in Aliases: gal, sal

It wouldn’t be right if the Alias cmdlets didn’t have their own aliases!

gal -> Get-Alias

PowerShell

1

2

3

4

5

6

7

8

PSC:\Users\aaron>gal-DefinitionGet-Alias

CommandType Name

---------------

Alias gal->Get-Alias

sal -> Set-Alias

PowerShell

1

2

3

4

PSC:\Users\aaron>sal-Namegcpi-ValueGet-ControlPanelItem

Recommended practice for using PowerShell Aliases

Feel free to use PowerShell Aliases when you are working interactively in the PowerShell console. And that’s it.

When writing scripts that are going to be reviewed, used, and updated by others, prioritize readability and use the full cmdlet name.