Extending Alias Functionality

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


Alias names are a good way of making commands more accessible. The following line would enable you to quickly launch Internet Explorer by entering the IE alias:

Set-Alias IE "$env:programfiles\Internet Explorer\iexplore.exe"

Aliases only replace commands so you can easily add parameters and arguments which are handed to the executable your alias points to. To open a specific Web page with your new IE alias, type this:

IE www.idera.com

Aliases can take arguments you add, but aliases cannot add arguments automatically. If you'd like to add a fixed set of arguments to a command, you need to use functions. The following simple function provides a shortcut to ping.exe with fixed arguments that ping only once and set a timeout:

function pingfast { ping.exe $args -n 1 -w 500 }

So when you now ping an IP-Address using your pingfast function, the function automatically adds the -n and -w parameters, allowing for a fast alternative to ping systems:


Posted Jun 24 2009, 08:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.