2017-07-26 201 views
0

我遇到了使用New-PSDrive连接到远程服务器的问题。远程服务器是基于Windows的,并且只有userA才有权写入。New-PSDrive:未找到网络路径

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

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 Ver。 5

回答

1

你为什么要为这个任务创建PSDrive?

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

如果你有他们的明文密码,这应该工作得很好。

+0

我收到以下错误: “文件系统提供程序只支持在新PSDrive来cmdlet的凭据没有 指定凭据重新进行操作。” – Adrian

+0

@Adrian使用这个例子逐字? – TheIncorrigible1

+0

看起来只有New-PSDrive支持凭证,而复制项目不支持。是因为我的PS版吗? (5) – Adrian