Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 新建PSDrive:未找到网络路径_Shell_Powershell_Permissions_Remote Access_Remote Server - Fatal编程技术网

Shell 新建PSDrive:未找到网络路径

Shell 新建PSDrive:未找到网络路径,shell,powershell,permissions,remote-access,remote-server,Shell,Powershell,Permissions,Remote Access,Remote Server,我在使用新PSDrive连接到远程服务器时遇到问题。远程服务器基于Windows,只有userA具有写入权限 通过这样说,下面的代码抛出一个“拒绝访问”错误: 第3行拒绝访问路径“$remoteServerPath” 代码: 现在,我试图包括凭据信息,但我得到了一个不同的错误 在第3行上找不到网络路径 谁能帮帮我吗Powershell版本。5为什么要为此任务创建PSDrive & NET USE Z: \\server\path /user:domain\UserA 'PASSWORD'

我在使用
新PSDrive
连接到远程服务器时遇到问题。远程服务器基于Windows,只有
userA
具有写入权限

通过这样说,下面的代码抛出一个“拒绝访问”错误:

第3行拒绝访问路径“$remoteServerPath”

代码:

现在,我试图包括凭据信息,但我得到了一个不同的错误

在第3行上找不到网络路径


谁能帮帮我吗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 cmdlet上的凭据。请在不指定凭据的情况下再次执行该操作”@Adrian使用此示例逐字记录?看起来只有New-PSDrive支持凭据,而复制项则不会。是因为我的PS版本吗?(5) @Adrian当然不是。您可以通过在控制台中使用
help命令
并查看语法来验证这些内容。您是否试图将网络驱动器映射为与登录用户不同的用户?是。没错。我是“userB”,对$Destination文件夹没有写权限,但只有userA有写权限。我甚至尝试以其他用户(userA)的身份运行PS,但没有成功…请在您的问题中显示
$remoteServerPath
分配。
$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
& NET USE Z: \\server\path /user:domain\UserA 'PASSWORD'
Copy-Item -Path $Source -Destination 'Z:\' -Force
& NET USE Z: /D