我正在尝试测试winrm是否可以在一系列系统上工作;但是,我似乎无法捕获/静默尝试连接到系统时出现的错误。它似乎可以在一个系统上工作:
PS C:\Users\Egr> winrm id -r:system1
IdentifyResponse
ProtocolVersion = http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor = Microsoft Corporation
ProductVersion = OS: x.x.xxxx SP: x.x Stack: x.x但在另一个上不起作用:
PS C:\Users\Egr> winrm id -r:system2
WSManFault
Message = WinRM cannot process the request. The following error occured while using Kerberos authentication: The net
work 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.
Error number: -2147024843 0x80070035
The network path was not found.我尝试过在try/catch块中包围它,但似乎没有让它安静下来。我正在尝试对这些系统运行一次检查,以确定哪些系统的WinRM配置正确且工作正常;但是,如果脚本一直输出此文本,它将不能很好地工作。有没有办法抑制这个文本,或者有没有更好的方法来测试WinRM连通性?
发布于 2013-08-13 04:49:33
您可以redirect the error stream到$null并评估$LastExitCode以检测错误:
$rhost = 'system2'
winrm id -r:$rhost 2>$null
if ($LastExitCode -eq 0) {
Write-Host "$rhost OK" -ForegroundColor green
} else {
Write-Host "$rhost unavailable" -ForegroundColor red
}https://stackoverflow.com/questions/18194516
复制相似问题