Development Powershell Tutorials

Powershell – Alias Investigation

The cmdlet and parameter names on Powershell are great because they’re easy to understand what they do.
Get-Process, Restart-Service, Get-Mailbox (Microsoft Exchange cmdlet, not available unless connected to Exchange Powershell) and Get-Date, all good examples this.

But Powershell is a scripting language so sometimes you’ll want to just bang out a few one liners, quick and dirty to get the job done.

This is where aliases comes in handy!

To help us with using aliases we have the cmdlet Get-Alias.
If we want to know an alias of a command we type:

Get-Alias -Definition Get-Process

Or if we want to know the real name of an alias we type:

Get-Alias cls
Cls, or Clear-Host, will clear the screen from all that has been written or

How much you use aliases is up to you but I find it saves a lot of time in the long run.
Below is a list of some of the aliases I use frequently:

  • cls = Clear-Host
  • ? = Where-Object
  • icm = Invoke-Command
  • Select = Select-Object
  • % = Foreach-Object
  • gm = Get-Member

And some aliases for parameters:

  • -exp = -ExpandProperty (Select-Object)
  • -ea = -ErrorAction (Common parameter found on most cmdlets)
  • ! = -not (used in comparisons eg. if statements which we’ll look at in a future post)

I’ll also mention briefly that you can add your own aliases with New-Alias but it is not something I have used so I wont go into that unless it’s requested.

Once we start talking about creating our own functions we’ll also touch on how to add aliases to our functions parameters.

As always, continue to learn and evolve your skills, see you in the next one!

Do you want to know more? Here is a list of tutorials to check next