简体   繁体   English

测试WinRM / WSMan连接性?

[英]Test WinRM/WSMan connectivity?

I'm trying to test if winrm works on a list of systems; 我正在尝试测试winrm是否在系统列表上工作; however, I can't seem to catch/silence the error that appears when I attempt to connect to a system. 但是,当我尝试连接到系统时,似乎无法捕捉/消除出现的错误。 It appears to work on one system: 它似乎可以在一个系统上运行:

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

But doesn't work on another: 但不适用于另一个:

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.

I've tried surrounding it in a try/catch block, but it doesn't seem to silence it. 我已经尝试将其围绕在try / catch块中,但是它似乎并没有使其静音。 I am attempting to run a check against these systems to determine which ones have WinRM configured correctly and working; 我试图对这些系统进行检查,以确定哪些系统已正确配置了WinRM并且可以正常运行; but if the script keeps outputting this text, it won't work very neatly. 但是,如果脚本继续输出此文本,它将无法很好地工作。 Is there any way to suppress this text, or is there a better way to test WinRM connectivity? 有什么方法可以禁止显示此文本,或者有更好的方法来测试WinRM连接?

You could redirect the error stream to $null and evaluate $LastExitCode to detect an error: 您可以将错误流重定向$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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM