我在使用New-PSDrive
连接远程服务器时遇到了问题。 远程服务器是基于Windows的,只有userA
有写入权限。
具体来说,以下代码会抛出“拒绝访问”错误:
第3行无法访问路径“$remoteServerPath”
代码:
New-PSDrive -Name remote -Root $remoteServerPath -PSProvider FileSystem
$destination = [IO.Path]::Combine('remote:', $fileName)
Copy-Item -Path $source -Destination $destination -Force
现在,我正在尝试包含凭据信息,但是出现了不同的错误!
第3行出现“网络路径未找到”的错误。
$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
$remoteServerPath
的赋值。 - Slogmeister Extraordinaire