Scott Hanselman

PUSHD reminder - it automatically maps network drives

July 31, 2006 Comment on this post [0] Posted in PowerShell
Sponsored By

I've blogged a few times about how cool PUSHD (and POPD) is from the cmd.exe prompt. It's one of the most powerful "DOS" commands that few folks use.

PUSHD, of course, maintains a stack of where you are in your file system. It will PUSH a directory on the stack and move you there automatically. Combined with a PROMPT variable that includes (somewhere) a $+, you'll get a very powerful way to move about.

Example from CMD>EXE:

C:\Documents and Settings\Scott>PUSHD c:\windows
C:\WINDOWS+>pushd system32
C:\Documents and Settings\Scott>

One thing that I don't see a lot is PUSHD with UNC Paths, and how it will automatically map a drive for you, starting at Z: moving backwrads and will unmap them when you POPD.

Example from CMD.EXE:

C:\Documents and Settings\Scott>PUSHD \\SCOTTPC\D
C:\Documents and Settings\Scott>cd
CMD does not support UNC paths as current directories.

But, of course, I can't CD to a UNC path with CMD.EXE.

However, all these scenarios, plus CD'ing to UNC paths work within Powershell:

PS C:\Documents and Settings\Scott> pushd \\scottpc\desktop
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\desktop> cd \\scottpc\d
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\d> cd \\scottpc\desktop
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\desktop> c:
PS C:\Documents and Settings\Scott> PUSHD
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\D> PUSHD \\SCOTTPC\DESKTOP
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\DESKTOP> POPD
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\D> POPD
PS C:\Documents and Settings\Scott> cd

Nice stuff to know. Thanks to Ryan Carr for the reminder.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.