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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
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 ended up using an Invoke-command to call NET USE

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CESNetwork AdministratorAuthor Commented:
I went a different route to achieve what was needed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.