Extending Alias Functionality

by Jun 24, 2009

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:programfilesInternet Exploreriexplore.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: