Avatar of CES
CES asked on

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?
Powershell

Avatar of undefined
Last Comment
CES

8/22/2022 - Mon
Jose Gabriel Ortega Castro

Good morning, just try like this:
New-PSDrive -Name "X" -PSProvider "FileSystem" -Root "\\webserver\Logs"

Open in new window

Or
$username="myusername@item.com"
$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.
ASKER CERTIFIED SOLUTION
CES

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
CES

I went a different route to achieve what was needed
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck