我不确定我是否使用 winrmcmd 正确配置了 TrustedHosts
我正在从 host_computer(工作组的一部分)在 PowerShell 中运行命令
$cred = Get-Credential -credential user
出现提示,我输入密码
然后我执行一个命令,以便 setup.exe 将在 remote_computer (也是工作组的一部分)上执行
invoke-command -ComputerName remote_computer -credential $cred -scriptBlock {& 'C:\share\setup.exe'}
出现错误:
[remote_computer] Connecting to remote server remote_computer failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client
computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the
TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (remote_computer:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionStateBroken
在 host_computer 我打开命令提示符(shift,右键单击,选择“以管理员身份运行”)并执行以下命令
C:\Windows\system32>winrm quickconfig
C:\Windows\system32>winrm e winrm/config/listener
C:\Windows\system32>winrm get winrm/config
C:\Windows\system32>winrm set winrm/config/service/auth @{Basic="true"}
C:\Windows\system32>winrm set winrm/config/service @{AllowUnencrypted="true"}
C:\Windows\system32>winrm set winrm/config/client @{TrustedHosts="remote_computer"}
在 remote_computer 我打开命令提示符(shift,右键单击,选择“以管理员身份运行”)并执行以下命令
C:\Windows\system32>winrm get winrm/config
C:\Windows\system32>winrm set winrm/config/client/auth @{Basic="true"}
C:\Windows\system32>winrm set winrm/config/client @{AllowUnencrypted="true"}
C:\Windows\system32>winrm set winrm/config/client @{TrustedHosts="host_computer"}
C:\Windows\system32>winrm identify -r:http://host_computer:5985 -auth:basic -u:user -p:password -encoding:utf-8
我得到以下回应
IdentifyResponse
ProtocolVersion = http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor = Microsoft Corporation
ProductVersion = OS: 6.3.9600 SP: 0.0 Stack: 3.0
SecurityProfiles
SecurityProfileName = http://schemas.dmtf.org/wbem/wsman/1/wsman/secprof
ile/http/basic, http://schemas.dmtf.org/wbem/wsman/1/wsman/secprofile/http/spneg
o-kerberos
现在当我去 host_computer 并执行
invoke-command -ComputerName remote_computer -credential $cred -scriptBlock {& 'C:\share\setup.exe'}
我不再收到任何错误消息,但是当我远程进入 remote_host 时,我在任务管理器中看不到 setup.exe。已经半个多小时了,我找不到文件被执行的任何证据。
如何排除故障?