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
Avatar of Jose Gabriel Ortega Castro
Jose Gabriel Ortega Castro
Flag of Venezuela, Bolivarian Republic of image

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
Avatar of CES
CES

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CES
CES

ASKER

I went a different route to achieve what was needed
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo