Extending Alias Functionality

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:

pingfast 10.10.10.10

Posted Jun 24 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.