首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测试WinRM/WSMan连接?

测试WinRM/WSMan连接?
EN

Stack Overflow用户
提问于 2013-08-13 02:53:55
回答 1查看 10.3K关注 0票数 3

我正在尝试测试winrm是否可以在一系列系统上工作;但是,我似乎无法捕获/静默尝试连接到系统时出现的错误。它似乎可以在一个系统上工作:

代码语言:javascript
复制
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

但在另一个上不起作用:

代码语言:javascript
复制
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连通性?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-13 04:49:33

您可以redirect the error stream$null并评估$LastExitCode以检测错误:

代码语言:javascript
复制
$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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18194516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档