Prof. Powershell

Creating EXE Aliases in PowerShell

Here's how to create an alias in PowerShell to save time.

In PowerShell, an alias is a handy shortcut or command alternative. For example, instead of typing Get-ChildItem, you can type ls or dir. Aliases can act as a transition from other shells to PowerShell as well as simplify typing. The great thing about an alias is that you can create your own for any command you can type at a command prompt.

To create a new alias, use the New-Alias cmdlet. No surprise there. All you need is the name of your new alias and the command that it will reference.

PS C:\> new-alias np notepad.exe

If the alias already exists, you will get an error, unless you use –Force. Or you can use Set-Alias. If the alias already exists it will be modified. Otherwise a new one will be created.

There's no limit to what you can define. I have a PowerShell window open all the time and I find it much easier to start apps like Word or Excel directly from the prompt, instead of hunting for a menu shortcut or desktop icon. I have these commands in my PowerShell profile:

Set-Alias wd "$env:Programfiles\Microsoft Office\Office15\winword.exe" -option ReadOnly
set-alias xl "$env:Programfiles\Microsoft Office\Office15\Excel.exe" -option ReadOnly
set-alias ie "$env:Programfiles\Internet Explorer\iexplore.exe" -option ReadOnly
set-alias pp "$env:Programfiles\Microsoft Office\Office15\Powerpnt.exe" -option ReadOnly

Notice the option parameter? Not that I am likely to do it, but I am defining the aliases as read-only to protect myself from accidentally overwriting it. Now all I need to do to launch Microsoft Word is this:

PS C:\> wd

I can add as many aliases as I'd like using Set-Alias or New-Alias:

new-alias pe G:\sysinternals\procexp.exe
new-alias who whoami.exe

I can use these aliases in PowerShell without having to modify my path or do a lot of typing.

PS C:\> pe /s:$pid

Using my new alias, I can launch Process Explorer from SysInternals and select the current PowerShell process.

Want to know what non-PowerShell commands you have aliased? Ask:

PS C:\> get-alias | where {$_.ReferencedCommand -match "exe"} | format-table Name,Definition -autosize

[Click on image for larger view.] 

As you can see in the figure, I don't have a lot of exe aliases but they definitely make my life easier.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular