The Blog

Using Network Locations with Command Prompt

If you have ever tried working with UNC paths with the CMD either at the console or using a batch file you likely have run into a problem like this:

CMD does not support UNC paths as current directories.

CMD does not support UNC paths

Luckily there are a couple useful commands to overcome this limitation. The commands are "pushd" and "popd".

'Pushd' used with a UNC path will mount the path as a network drive and automatically save the network drive to it's working directory.

pushd \\server\share

PushdPushd has mapped our network path to the first available drive letter 'X' and automatically changed our working directory.

We can now run commands against our network location.

CMD on UNC Path CommandsWe created and then listed a folder on our network location.

To disconnect the share we can simply use the 'popd' command.


PopdOur mapped network location is now disconnected.

This is how it may look in a batch file.

@echo off
pushd "\\Server\Share\Folder"
"Commands to execute"






Neil Bryan
IT Consultant & Technical Trainer
Neil Bryan is an IT consultant and technical trainer specializing in VMware, Citrix and Microsoft virtualization and infrastructure.

Leave a Reply

Skip to toolbar