Cannot map network drives in PowerShell

Hi All,

I have a network share that is accessible via unc path and I can also map it as a drive using NET USE in command prompt.

However I am writing a PowerShell script that will need to map this drive as part of it and I am having problems mapping it using the New-PSDrive cmdlet.

This is the syntax that I believe should work based on what I've read online:
New-PSDrive X -PSProvider FileSystem -Root \\webserver\Logs\ -Credential $webuser

However I am receiving the below error when trying to run the command:

The specified drive root "\\webserver\Logs\" either does not exist, or it is not a folder.

I have tried with/without quotes and have included or excluded the final "\" with no luck.

Does anyone have any suggestions as to what I may be doing wrong?
CESNetwork AdministratorAsked:
Who is Participating?
CESNetwork AdministratorAuthor Commented:
I ended up using an Invoke-command to call NET USE
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Good morning, just try like this:
New-PSDrive -Name "X" -PSProvider "FileSystem" -Root "\\webserver\Logs"

Open in new window

$creds = Get-credential -username $username -Message "Insert the password for the user $username"
New-PSDrive -Name "X" -PSProvider "FileSystem" -Root "\\webserver\Logs" -Credential $creds

Open in new window

The "\" at the end is irrelevant.
CESNetwork AdministratorAuthor Commented:
I went a different route to achieve what was needed
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.