SEARCH

How-To Geek

How to Map Network Drives Using PowerShell

image

In years past, automating network drive creation required the use of primitive batch files, luckily for us you can now do it through PowerShell.

Note: this tutorial expects that you are using PowerShell 3.0.

How to Map Network Drives Using PowerShell

Prior to the PowerShell era, we could map networks drives using a batch file that contained a net use command:

net use M: \\touchsmart\Share /Persistent:Yes

sshot-0

To do it in PowerShell, press the Win + R keyboard combination to bring up a run box, then type powershell and hit enter.

sshot-1

The Cmdlet we are looking for is New-PSDrive, but most importantly you need use the -Persist switch.

New-PSDrive –Name “K” –PSProvider FileSystem –Root “\\touchsmart\share” –Persist

Just change the name to a valid (not in use) drive letter and point the root parameter to a valid network share.

sshot-2

That’s all there is to it.

Taylor Gibb is a Microsoft MVP and all round geek, he loves everything from Windows 8 to Windows Server 2012 and even C# and PowerShell. You can also follow him on Google+

  • Published 12/31/12

Comments (11)

  1. Don

    I think I’ll stick with the batch files. I really don’t see how this powershell method is any easier, faster or better unless someone can point out other advantages to it.

  2. MAN

    THIS WAS A NICE

  3. David

    I’m with Don. Unless you are into writing complex powershell scripts for other reasons this seems to offer no advantage.

  4. Alan

    Just an FYI this requires the PS 3.0 update which enables the persist switch – I attempted this with PS 2 and the persist switch was not recognized
    The powershell 3.0 update can be downloaded at the following
    http://www.microsoft.com/en-us/download/details.aspx?id=34595

  5. Paul

    If this solves the issue with disconnecting mapped network drives after restart I’m all for it, but it threw an error for me; here’s the command I used; New-PSDrive -Name “Y” -PSProvider Filesystem -Root “\\NAS\Volume_1″ -Persist This results in; New-PSDrive : A parameter cannot be found that matches parameter name ‘Persist’. So firstly am I doing something wrong, and secondly, is this really going to provide consistent persistence? Happy new year friends!

  6. VDIAS

    from a fast and small script to a bigger and more complex… great advantage…

  7. Frank

    @Paul It might depend on what version of powershell you have. They’re up to version 3.0 now. Don’t quote me on that though.

    Also I remember when I was going to school and an instructor said we should all learn powershell, it’s the future. While it is cool in some respects, it also makes some formerly simple commands more complicated like the example here.

  8. Richard

    Powereshell and mounting CIFS, HAHAHAHAHAHAHAHAhAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHA.
    sorry….
    MS KOKOTS.
    stop trying. linux rulez

  9. Alex

    @Don, @David it isn’t any faster, but the old way still works in PowerShell. In fact, most old commands work fine (you just have to be careful with quotes, which PS wants to interpret as strings).

    PowerShell’s strength isn’t in a single command, its in what you can do by stringing a set of commands together via the pipeline. Often times a single line of PowerShell can replace very long and complex VB and batch scripts. Google for PowerShell one liners and you’ll see what I mean.

    It may seem like a steep learning curve, but its totally worth it!

    @Paul – Frank is correct. The persist parameter is new with PowerShell v3. Without it, you’re better off using net use from your PowerShell scrips as the drive won’t exist outside of your PowerShell session.

  10. Shahzad

    Powershell is future technology. Its a good time to start using it, will be much easier in future.

  11. Erik

    The problem with PowerShell, is that it doesn’t maintain compatibility with many standard command line commands. Safer to stick with the more widely-used standard.

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!