Adrian Adrian - 1 year ago 74
Bash Question

New-PSDrive : The network path was not found

I am having an issue to connect to the remote server using

. The remote server is Windows-based, and only
has access to write.

By saying that, the following code throws an "access denied" error:

Access to the path '$remoteServerPath' is denied on line3


New-PSDrive -Name remote -Root $remoteServerPath -PSProvider FileSystem
$destination = [IO.Path]::Combine('remote:', $fileName)
Copy-Item -Path $source -Destination $destination -Force

Now, I am trying to include credential information, but I get a different error!

The network path was not found on line3

$secpass = ConvertTo-SecureString 'myPassword' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('domain\userA', $secpass)
New-PSDrive -Name remote -Root $remoteServerPath-PSProvider FileSystem -Credential $cred
$destination = [IO.Path]::Combine('remote:', $fileName)
Copy-Item -Path $source -Destination $destination -Force

Can anyone please help me out? Powershell Ver. 5

Answer Source

Why are you creating a PSDrive for this task?

& NET USE Z: \\server\path /user:domain\UserA 'PASSWORD'
Copy-Item -Path $Source -Destination 'Z:\' -Force

If you have their plaintext password, this should work just fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download