Take the 2-minute tour ×

I often access shared network folders in Powershell to grab files etc. But if the share requires a username/password, Powershell does not prompt me for these, unlike Windows Explorer. If I connect to the folder first in Windows Explorer, Powershell will then allow me to connect.

How can I authenticate myself in Powershell?

share|improve this question

4 Answers 4

up vote 22 down vote accepted

At first glance one really wants to use New-PSDrive supplying it credentials.

> New-PSDrive -Name P -PSProvider FileSystem -Root \\server\share -Credential domain\user


New-PSDrive : Cannot retrieve the dynamic parameters for the cmdlet. Dynamic parameters for NewDrive cannot be retrieved for the 'FileSystem' provider. The provider does not support the use of credentials. Please perform the operation again without specifying credentials.

The documentation states that you can provide a PSCredential object but if you look closer the cmdlet does not support this yet. Maybe in the next version I guess.

Therefore you can either use net use or the WScript.Network object, calling the MapNetworkDrive function:

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("u:", "\\server\share", $false, "domain\user", "password")

Edit for New-PSDrive in PowerShell 3.0

Apparently with newer versions of PowerShell, the New-PSDrive cmdlet works to map network shares with credentials!

New-PSDrive -Name P -PSProvider FileSystem -Root \\Server01\Public -Credential user\domain -Persist
share|improve this answer
There's an open bug for this: connect.microsoft.com/feedback/… –  halr9000 Nov 20 '08 at 21:21
Actually, I think the cmdlet supports it just fine - it's the underlying PSDrive provider that isn't doing anything with it. All the *-Item cmdlets have a generic set of behaviors; they just pass them through to the PSDrive provider, though. -filter is another example. –  Don Jones Nov 29 '08 at 17:22
Note that as of Powershell 3.0, you can pass credentials when connecting a drive to UNC paths, and if you use the -Persist option, the drive will be created as a normal Windows mapped drive. –  Bacon Bits Dec 15 at 14:14
@BaconBits. Thank you for letting me know on this! I've updated the question to reflect the 3.0 version of PowerShell. –  Scott Saad Dec 17 at 5:01

This is not a PowerShell-specific answer, but you could authenticate against the share using "NET USE" first:

net use \\server\share /user:<domain\username> <password>

And then do whatever you need to do in PowerShell...

share|improve this answer
This is one of those "use what works" cases where I agree with Anon. Normally, I would go out of my way to provide a PowerShell answer but not this time. :) –  halr9000 Nov 20 '08 at 15:28
This is good way to access windows share from other languages. –  Trismegistos Jan 16 at 16:17

PowerShell 3 supports this out of the box now.

If you're stuck on PowerShell 2, you basically have to either use the legacy net use command (as suggested earlier), or the network Impersonation module that I wrote a while back (specifically to address this).

share|improve this answer

On the same machine, I try the same NET USE command from a regular command prompt, and from a PowerShell v2 command prompt:

NET USE Link : SharePoint

In CMD it works just fine.

In PS, it says it works fine, and the drive is mapped. However, mostly the drive's status as listed when you type just NET USE is blank, and the drive mapping doesn't work (i.e. you cannot get data from the mapped drive).

It might be a SharePoint issue as the NET USE from powershell sometimes works, sometimes don't, but still it appears that there's a difference between CMD and PS.

share|improve this answer
Did you ever resolve this Bhavesh? I am having a similar issue on startup.cmd of my web role, net use statement wont map drive but if i do it from cmd prompt it works fine –  Jay Jul 29 at 8:24

Your Answer


