About the author

My name is Donovan Brown and I am a Principal DevOps Manager with Microsoft with a background in application development. I also run one of the Nation’s fastest growing online registration sites for motorsports events DLBRacing.com. When I am not writing software I race cars for fun. DLBRacing.com has given me the opportunity to combine my two passions writing software and racing cars.

In this post I am going to add one more that allows you to go up several levels in your path without having to repeatedly type .. over and over again. The new function is called Backup-Location with an alias of bu.

If you are continuing from my previous posts and used the same utils.ps1 file you are done.

If you are starting with this post, save the file so you we can dot source the file in our PowerShell profile. I named my file utils.ps1 and saved it in C:\Users\me\Documents\WindowsPowerShell\Scripts.

Now we must update our profile to dot source the file we just created. Start PowerShell and type the following:

code $Profile

This will start Code with your current profile script loaded or create a new file for you if you do not already have one.

Add to the bottom of the file

. C:\Users\me\Documents\WindowsPowerShell\Scripts\utils.ps1

Now just save and close the file. Now every new PowerShell session you start you will be able to use bu to navigate back several levels at a time.

Thanks for the script. I love the way you describe your powershell Synopsis. But why is the command not coherent with the description? It would make way more sense to use set-locationlevel or something similar.

You can use CD ~ to move back to your home directory or just type the literal path c:\users..
I guess if u find this command useful you are navigate quite a lot..
You could also use * for building the string easier
$sb="../"*$Levels
Nice coding ,good job