Remembering where you've been in Powershell with pushd and popd

The other day I discovered a long existing pair of commands in Powershell that allows one to navigate to a directory and then back to the previous one without having to manually maintain a stack of directories. The two commands are pushd and popd.

A quick bit of searching shows that these commands have existed in Unix shells for many years as well as Powershell since version 2. Wikipedia -- Pushd and popd

Where I have found this really useful recently is in deployment scripts where I need to change the current directory in the script but for usability I want to go back to where the script was first called from should any errors occur or even if the script finishes successfully. By using a try/catch/finally pattern this allows me to put the user back where they started with confidence whenever they execute the script.

try
{
pushd DIRECTORYPATH
# Logic goes here
}
catch
{
# Make sure any exceptions are bubbled up
throw $_
}
finally
{
popd
}

TechNet -- Push-Location
TechNet -- Pop-Location

Mythical Man Month

This is such an awesome book I thought it useful to educate more people on its existence.

The iconic book by Fred Brooks covers many of the lessons he learnt during his time as a project manager of the IBM System 360 project. The book is separated into sections that cover a topic at a time and have suggestions for avoiding the issues he ran into. 40 years later we are still running into the same problems on projects today. A must read for any tech lead and highly recommended for any developer who thinks they will end up on a project where they are either the sole dev or one of a couple, basically any dev ever.