Powershell-远程执行服务器上的脚本

时间:2017-07-15 20:28:21

标签: powershell cross-domain

我正在尝试从server01运行powershell脚本。我在server03上有帐户,因此没有通过凭据。即使我通过它,也会出现相同的错误消息。

我的帐户在domainA和server01上,而服务器03在domainB上。如果我使用属于DomainB的另一个帐户登录到server01,则该脚本可以正常工作。

在我跨域PS执行之前还有什么我需要启用的吗?

Invoke-Command -ComputerName server03 -FilePath E:test\test.ps1

[Server03] Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: The network path was not found.
 Possible causes are:
  -The user name or password specified are invalid.
  -Kerberos is used when no authentication method and no user name are specified.
  -Kerberos accepts domain user names, but not local user names.
  -The Service Principal Name (SPN) for the remote computer name and port does not exist.
  -The client and remote computers are in different domains and there is no trust between the two domains.
 After checking for the above issues, try the following:
  -Check the Event Viewer for events related to authentication.
  -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or us
e HTTPS transport.
 Note that computers in the TrustedHosts list might not be authenticated.
   -For more information about WinRM configuration, run the following command: winrm help config. For more information,
 see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

2 个答案:

答案 0 :(得分:0)

我已经为服务器添加了FDQN,它运行正常。

Invoke-Command -ComputerName server03.domain.com -FilePath E:test \ test.ps1

答案 1 :(得分:0)

  • 您需要将计算机添加到“受信任的主机”列表中。

  • 检查属于受信任主机列表的服务器。

    Get-Item WSMan:\localhost\Client\TrustedHosts

    Set-Item WSMan:\localhost\Client\TrustedHosts -Value “IPAddress or *”

然后继续执行命令。