Wednesday, January 4, 2012

Powershell (v2) - Use Set-Alias in Profile for Commonly Used Paths

Sometimes I get to working on a project and start using a given set of directories so often I add quick ways to get to these folders.  So, let's say I am working on a project called Analysis and my files are stored in C:\users\will\documents\powershell\analysis.  To save myself a ton of repetitive typing, I will add the following to my $profile:
function Open-Analysis {
  Set-Location C:\users\will\documents\powershell\analysis;
}
Set-Alias -Name Analysis -Value Open-Analysis;
After I save the file and start a new PSSession, I can now type analysis and hit [Enter] and I will automatically be at the folder I need in 9 keystrokes.  When I am done with the project, just remove the function and Set-Alias call and I'm done.

0 comments:

Post a Comment