Command line network drive quickies

The most common way to connect a drive to a network path in Windows is this command:

net use X: \\SERVER\Share

Where:

  • X: is the drive letter you wish to map the share to,
  • \SERVER\Share is the UNC path to the share.

Assuming you have permissions to map drives and to access that share, it will map the drive and tell you that it mapped successfully.

If you want quick access and do not want to map a network drive, you can access a UNC Path directly from the Command Prompt using pushd.

For example:

pushd \\SERVER\Share

This will connect to the path automatically for you and make it your current working directory.

When you are finished on the network share enter the popd command. This will return you to the directory you were in before and delete the temporary network drive.

The popd and pushd commands can be used with local directories. If change to a directory with pushd it stores the previous location you were in so that when you issue the popd command you are returned to it. This is similar to bash-stacking in linux where if you open a shell within an existing shell, quitting that will take you back to where you were when you opened it.



#active directory #command line #Computers #file sharing #networking #Programming #server #windows