How to create a new drive from an UNC path in PowerShell (or Command Prompt)

PowerShell or Command Prompt?

PowerShell.
Command prompt is no longer refreshed. Where PowerShell is now the ‘new’ default.

Click here if you’d like to know how much it differs from each other.

This post initially contained only Command Prompt.
PowerShell has now been added.

Are you missing anything? Then let me know in a comment.


Let’s create a new drive with PowerShell.

Since it is much easier with PowerShell I haven’t made a techy and Dummy post.

Start PowerShell_ISE.

Type in the following command. Don’t run it yet as we’ll make some changes.

New-PSDrive -Name “D” -PSProvider “FileSystem” -Root “\\HOST\Directory”

  • Change the -Name to whatever you want to name it.
  • Change -Root to the PSDrive location.

My Example:

Let's create a new drive with PowerShell
Let’s create a new drive with PowerShell.

For more about New-PSDrive with more examples, please click here.


A little extra

This post contains PowerShell. Would you like to learn the basics better? I have created a new website to learn basic PowerShell in an ’emulator’ environment.
Click here to go learn Basic PowerShell.


Let’s create a new drive with Command Prompt.

Just like PowerShell, I also have two versions for Command Prompt. one for the techies and the other for the dummies with screenshots.

Legacy Content:

Opening a directory with Command prompt could be useful for example: open a directory on a different computer or server. Or open a directory on a NAS for a back-up. This way you can program a script that will open this temporarily directory and write the back-up to this letter.


Let’s create a new drive with Command Prompt for the techies among us.

If you’re using Command Prompt it will create a network drive with the last letter possible in the alphabet. So for me that’s Z:\.

Go to Start and search for CMD.
Start CMD and type in the following:

pushd \\hostname\directory

That’s it. You’ll now have a temporarily drive with the last letter in the alphabet available.


Let’s create a new drive with Command Prompt for the dummies among us.

Go to Start and search for CMD.
Open CMD.

How to create a new drive from an UNC path in Command Prompt
How to create a new drive from an UNC path in Command Prompt.

Type the following command in Command Prompt.

pushd \\hostname\directory

How to create a new drive from an UNC path in Command Prompt
How to create a new drive from an UNC path in Command Prompt.

If you’d like to know more about Pushd you could also type in pushd /?

In the example below I used my own laptop as the host name and my user directory as a new drive mapping.

How to create a new drive from an UNC path in Command Prompt.
How to create a new drive from an UNC path in Command Prompt.

 

Legacy Content

The blog originally dates from April 11, 2015.
I doubt if anyone is really looking for this, but because I think it’s a shame to delete the blog post, I have renewed it anyway.
Maybe someday there will be a day when the content will become current again and then I will have it for you.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work full-time as a Services Engineer. In my spare time I write about the error messages that I encounter during my work. Furthermore, I am currently occupied with Office 365, Azure infrastructure, and PowerShell for automating daily tasks.

Leave a Reply

Your email address will not be published. Required fields are marked *