PowerShell- 在远程计算机上执行脚本时出现错误

6
以下内容对我没有起作用 -
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command "& Invoke-Command -ComputerName "Spider_LT_86" -ScriptBlock { msiexec.exe /i "D:\3PDInstallers\ETLBackgroundWorkerSetup.msi" /qn /l*vx "D:\3PDInstallers\logs" }"

所有我需要做的就是在远程机器上运行msiexec。我假设运行脚本的用户将具备访问远程机器所需的权限。
即使Computername指向本地计算机(而使用相同登录用户运行msiexec时工作正常,因此看起来不像是权限问题),脚本也无法正常工作-我已确保WinRM服务正在运行,并且还禁用了防火墙以检查是否造成了问题,但迄今为止没有任何运气。我错过了什么?
这是完整的错误消息,但它几乎列出了所有可能性-
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 use 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 He
lp topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

更新:

当我只使用用户名和 -Credentials 时,它会弹出一个登录窗口来获取我的密码,然后在输入密码后,会给出以下错误提示-该用户确实具有管理员访问权限,所以我不知道问题出在哪里。

[spider_lt_86] 连接到远程服务器失败,错误信息如下:拒绝访问。有关更多信息,请参见 about_Remote_Troubleshooting 帮助主题。 + CategoryInfo : OpenError: (:) [], PSRemotingTransportException + FullyQualifiedErrorId : PSSessionStateBroken


2
尝试在远程主机上执行 enable-psremoting -force 命令。 - Loïc MICHEL
1
当您在命令中添加-Credential“用户名”时会发生什么? - Stanley De Boer
@Kayasax 这也不起作用 - 我已经将连接更改为工作状态,而不是公共状态,甚至禁用了连接并尝试本地连接 - 它仍然无法正常工作。 - Roopesh Shenoy
1
您的帐户可能不是远程管理员组的成员,您应该在这里查看:http://technet.microsoft.com/zh-cn/library/hh847850.aspx - Loïc MICHEL
啊,成功了!我仍然需要想办法不硬编码用户名/密码,但至少这是一个开始...感谢Kayasax和StanleyDeBoer,如果你们来印度,我欠你们一杯啤酒! - Roopesh Shenoy
显示剩余11条评论
3个回答

3

2
一件事很明显,错误信息“未找到网络路径”并没有显示出底层问题的原因。我在Microsoft论坛上看到一个帖子,其中一个回复者说它以前能用,现在不能用了。这就是我所发现的情况。我验证了我可以ping通和查看共享文件夹,所以我知道网络部分是正常的。我重新启动了源服务器,但似乎没有帮助。一旦我重新启动了目标服务器,WinRM错误就消失了,一切都重新开始工作了。不清楚是某个服务停止或者出现问题,还是有其他不太明显的问题。重启后我又遇到了一个失败(大约20次尝试中的一个),但在我们的环境中,随机失败并不罕见。如果这能帮助其他人,我会留下这份记录。

2
你是否在计算机上设置了 TrustedHosts 以允许你连接到其他计算机?
请在您尝试远程控制的计算机上运行此命令。
Set-Item  wsman::localhost\client\TrustedHosts *  
Restart-Service WinRm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接