New-PSDrive:找不到网络路径
New-PSDrive : The network path was not found
我在使用 New-PSDrive
连接到远程服务器时遇到问题。远程服务器基于 Windows,只有 userA
具有写入权限。
也就是说,以下代码会引发 "access denied" 错误:
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
现在,我尝试包含凭据信息,但出现了不同的错误!
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
谁能帮帮我? Powershell 版本。 5
为什么要为此任务创建 PSDrive?
& NET USE Z: \server\path /user:domain\UserA 'PASSWORD'
Copy-Item -Path $Source -Destination 'Z:\' -Force
& NET USE Z: /D
如果你有他们的明文密码,这应该没问题。
我在使用 New-PSDrive
连接到远程服务器时遇到问题。远程服务器基于 Windows,只有 userA
具有写入权限。
也就是说,以下代码会引发 "access denied" 错误:
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
现在,我尝试包含凭据信息,但出现了不同的错误!
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
谁能帮帮我? Powershell 版本。 5
为什么要为此任务创建 PSDrive?
& NET USE Z: \server\path /user:domain\UserA 'PASSWORD'
Copy-Item -Path $Source -Destination 'Z:\' -Force
& NET USE Z: /D
如果你有他们的明文密码,这应该没问题。