使用Powershell将文件从一个远程服务器复制到另一个远程服务器
我正在尝试使用Powershell将文件从服务器A复制到服务器B。这两台服务器都属于我们的托管提供商,因此将文件从A复制到B比将文件从我的本地设备复制到任意一台服务器都要快。 我想我可以使用Powershell在serverA上运行远程命令并将文件复制到serverB。这就是我想到的:使用Powershell将文件从一个远程服务器复制到另一个远程服务器,powershell,powershell-2.0,Powershell,Powershell 2.0,我正在尝试使用Powershell将文件从服务器A复制到服务器B。这两台服务器都属于我们的托管提供商,因此将文件从A复制到B比将文件从我的本地设备复制到任意一台服务器都要快。 我想我可以使用Powershell在serverA上运行远程命令并将文件复制到serverB。这就是我想到的: $SourceServerName = "serverA" $SourceContentPath = "\\serverA\c$\testSrc" $DestinationContentPath = "\\ser
$SourceServerName = "serverA"
$SourceContentPath = "\\serverA\c$\testSrc"
$DestinationContentPath = "\\serverB\c$\testDest"
Invoke-Command -ComputerName $SourceServerName -ScriptBlock {param ($SourcePath,$InstallPath)
Copy-Item -Path $SourcePath\* -Destination $InstallPath -Recurse
} -ArgumentList $SourceContentPath, $DestinationContentPath
但是我得到一个错误“System.Management.Automation.RemoteException:对路径'testDest'的访问被拒绝
我是管理员,WinRM在这两个框上都配置正确。如果我尝试在同一台服务器内远程复制文件(即从\\serverA\c$\testSrc复制到\\serverA\c$\testDest),一切正常
正确的方法是什么?
调用命令是在当前用户(您当前登录到计算机的用户)下执行的。您应该将-Credential
调用命令的参数设置为目标系统的管理员用户服务器A上的cmdlet不会像您一样执行
两种可能的解决办法:
最简单的:
域用户解决方案:
如果您是域用户,并且可以控制这两台计算机,则只需通过本地计算机和服务器a上的启用WSManCredSSP
在PowerShell中启用CredSSP,然后在调用命令中添加-Authentication CredSSP
,运行PowerShell的帐户应该是这两个框的管理员。您应该还要检查serverB上的c:\testDest是否对您正在使用的帐户具有良好的权限。
$SourceServerName = "serverA"
$SourceContentPath = "\\serverA\c$\testSrc"
$DestinationContentPath = "\\serverB\c$\testDest"
$cred = Get-Credential # input your username and password of serverB here
Invoke-Command -ComputerName $SourceServerName -ScriptBlock {param ($SourcePath,$InstallPath, $cred)
Copy-Item -Path $SourcePath\* -Destination $InstallPath -Recurse -Credential $cred
} -ArgumentList $SourceContentPath, $DestinationContentPath, $cred