We help IT Professionals succeed at work.

Cannot map network drives in PowerShell

CES
CES asked
on
324 Views
Last Modified: 2018-01-21
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?
Comment
Watch Question

Jose Gabriel Ortega CastroCEO Faru Bonon IT&Agency /Top-Rated Freelancer (Upwork)/Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
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.
Network Administrator
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CESNetwork Administrator
CERTIFIED EXPERT

Author

Commented:
I went a different route to achieve what was needed

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.