【发布时间】:2016-05-27 14:38:51
【问题描述】:
我正在尝试从本地主机上的远程计算机复制一些文件,但抛出以下错误消息:
[remoteHost_IP] Connecting to remote server <IP> failed with the following error message : Access is denied. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (<remoteHost_IP>:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
出于测试目的,我使用以下脚本:
Param([string] $username, [string] $password)
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,(ConvertTo-SecureString $password -AsPlainText -Force)
$storage = "\\localhost's_IP\D$\testfile"
Invoke-Command -ComputerName <remote_comp'sIP> -Credential $credentials{ Copy-Item -Path "C:\Users\<localuser_memberOFlocalAdministratorsGroup>\desktop\testfile\asd.txt" -Destination $storage -Force -Recurse}
Enable-PSRemoting 已在两台主机上执行,而且每台主机都是另一台主机的 TrustedHosts 列表的一部分。
作为操作系统,我使用的是WS2012R2,Powershell的当前版本是4.0。
你能给我一些关于如何解决这个问题的想法吗?谢谢!
[编辑]
正如我所说,我正在使用 PowerShell 4.0(在我的情况下还不能升级到最新版本)。无论如何,我已经尝试过@vonPryz 的建议,现在我看不到任何错误消息,但文件仍然没有复制到本地主机上。这是我的代码[添加内容部分工作正常]:
$sessiona = New-PSSession -Name sesegnon -ComputerName "10.bla-bla" -Credential $credentials
$any_error = Invoke-Command -Session $sessiona -ScriptBlock {
Add-Content -Path "D:\path\int.txt" -Value "message"
Copy-Item -Path "D:\path\asd.txt" -Destination $storage -Force
$x = $error[0] | Out-String
return $x
}
Write-Host $any_error
【问题讨论】:
-
互动
Enter-PSSession工作吗? -
当您使用 Invoke-Command 访问网络资源时,您应该使用 CredSSP 身份验证而不是 Default。 " 注意:凭据安全支持提供程序 (CredSSP) 身份验证,其中用户的凭据被传递到远程计算机进行身份验证,设计用于需要对多个资源进行身份验证的命令,例如访问远程网络共享。这种机制增加了远程操作的安全风险。” 完整的 TechNet link
标签: powershell powershell-remoting powershell-4.0