0

我想要Get-NlbClusterNode包含状态的项目"Converged"(Enum of [Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatusCode]

我尝试过这样的事情:

Get-NlbClusterNode | %{ $_.State | ?{$_.ToString() -eq "Converged"} }

但这让我只有匹配状态

我试过contains运营商

Get-NlbClusterNode | ?{ $_.State -ccontains "Converged"}
# or
Get-NlbClusterNode | ?{ $_.State -ccontains [Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatusCode]::Converged}

但这对以太不起作用。

这是 PowerShell 对象

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Collections.Generic.List`1[[Microsoft.NetworkLoadBalancingClusters.PowerShell.Node, Microsoft.NetworkLoadBalancingClusters.PowerShell, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]</T>
      <T>System.Object</T>
    </TN>
    <LST>
      <Obj RefId="1">
        <TN RefId="1">
          <T>Microsoft.NetworkLoadBalancingClusters.PowerShell.Node</T>
          <T>System.Object</T>
        </TN>
        <ToString>Server02</ToString>
        <Props>
          <Obj N="Cluster" RefId="2">
            <TN RefId="2">
              <T>Microsoft.NetworkLoadBalancingClusters.PowerShell.Cluster</T>
              <T>System.Object</T>
            </TN>
            <ToString />
            <Props>
              <S N="Name"></S>
              <S N="ClusterIPAddress">192.168.0.20</S>
              <S N="ClusterNetworkMask">255.255.255.0</S>
              <S N="ClusterMacAddress">03-12-c0-a8-56-ac</S>
              <S N="OperationMode">MULTICAST</S>
              <B N="BdaReverseHash">false</B>
              <B N="BdaTeamActive">false</B>
              <Nil N="BdaTeamId" />
              <B N="BdaTeamMaster">false</B>
            </Props>
            <MS>
              <S N="ClusterName"></S>
              <S N="IPAddress">192.168.0.20</S>
            </MS>
          </Obj>
          <S N="Name">Server02</S>
          <S N="InterfaceName">NLB</S>
          <S N="Host">Server02</S>
          <Obj N="State" RefId="3">
            <TN RefId="3">
              <T>Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatus</T>
              <T>System.Object</T>
            </TN>
            <ToString>Converged</ToString>
            <Props>
              <S N="NodeStatusCode">Converged</S>
            </Props>
          </Obj>
          <I32 N="HostPriority">4</I32>
          <S N="AdapterGuid">{8FEAE540-F32E-42D0-940B-6E34E5977E77}</S>
          <Obj N="InitialHostState" RefId="4">
            <TN RefId="4">
              <T>Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeInitialHostState</T>
              <T>System.Enum</T>
              <T>System.ValueType</T>
              <T>System.Object</T>
            </TN>
            <ToString>Started</ToString>
            <I32>1</I32>
          </Obj>
          <B N="PersistSuspendOnReboot">false</B>
          <B N="MaskSourceMac">true</B>
          <I32 N="FilterIcmp">0</I32>
          <I32 N="GreDescriptorTimeout">10</I32>
        </Props>
      </Obj>
      <Obj RefId="5">
        <TNRef RefId="1" />
        <ToString>Server01</ToString>
        <Props>
          <Ref N="Cluster" RefId="2" />
          <S N="Name">Server01</S>
          <S N="InterfaceName">NLB</S>
          <S N="Host">Server01</S>
          <Obj N="State" RefId="6">
            <TNRef RefId="3" />
            <ToString>Converged(default)</ToString>
            <Props>
              <S N="NodeStatusCode">Default</S>
            </Props>
          </Obj>
          <I32 N="HostPriority">3</I32>
          <S N="AdapterGuid">{B47F1065-2E61-49A9-BFBB-E172EA9444E6}</S>
          <Obj N="InitialHostState" RefId="7">
            <TNRef RefId="4" />
            <ToString>Started</ToString>
            <I32>1</I32>
          </Obj>
          <B N="PersistSuspendOnReboot">false</B>
          <B N="MaskSourceMac">true</B>
          <I32 N="FilterIcmp">0</I32>
          <I32 N="GreDescriptorTimeout">10</I32>
        </Props>
      </Obj>
    </LST>
  </Obj>
</Objs>

这是类型Microsoft.NetworkLoadBalancingClusters.PowerShell.Node

   TypeName: Microsoft.NetworkLoadBalancingClusters.PowerShell.Node

Name                   MemberType Definition
----                   ---------- ----------
Equals                 Method     bool Equals(System.Object obj)
GetHashCode            Method     int GetHashCode()
GetType                Method     type GetType()
ToString               Method     string ToString()
AdapterGuid            Property   string AdapterGuid {get;set;}
Cluster                Property   Microsoft.NetworkLoadBalancingClusters.PowerShell.Cluster Cluster {get;set;}
FilterIcmp             Property   int FilterIcmp {get;set;}
GreDescriptorTimeout   Property   int GreDescriptorTimeout {get;set;}
Host                   Property   string Host {get;set;}
HostPriority           Property   int HostPriority {get;set;}
InitialHostState       Property   Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeInitialHostState InitialHost
InterfaceName          Property   string InterfaceName {get;set;}
MaskSourceMac          Property   bool MaskSourceMac {get;set;}
Name                   Property   string Name {get;set;}
PersistSuspendOnReboot Property   bool PersistSuspendOnReboot {get;set;}
State                  Property   Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatus State {get;set;}
4

3 回答 3

1

我使用以下内容:

$objClusterNode = Get-NlbClusterNode $env:COMPUTERNAME
[string]$strStatus = $objClusterNode | select -expand state 
if ($strStatus -ne "Converged") {Do stuff}

奇迹般有效!

于 2015-09-15T12:52:33.460 回答
0
Get-NlbClusterNode | ?{$_.State.NodeStatusCode -eq [Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatusCode]::Converged}

或者

Get-NlbClusterNode | ?{$_.State.NodeStatusCode -eq "Converged"}

因为该State属性有另一个属性NodeStatusCode

PS C:\Windows\system32> Get-NlbClusterNode | %{$_.State | Get-Member}


   TypeName: Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatus

Name           MemberType Definition
----           ---------- ----------
Equals         Method     bool Equals(System.Object obj)
GetHashCode    Method     int GetHashCode()
GetType        Method     type GetType()
ToString       Method     string ToString()
NodeStatusCode Property   Microsoft.NetworkLoadBalancingClusters.PowerShell.NodeStatusCode NodeStatusCode {get;set;}
于 2020-02-20T09:58:07.410 回答
0

所以我也一直在研究这个,并提出了以下建议。请注意,我的节点中有 2 台服务器,因此 [0] 返回 1009 代码,即“已融合(默认)” [1] 返回代码 1008 已融合。

 if ((Get-NlbClusterNode -HostName <Name>).state[0].NodeStatusCode.value__ -ne "1008") {write-host "not 1008"} else {Write-Host "it is 1009"}

如果您只是文本输出,这也可以相当快地获取信息。我现在正在讨论如何自己处理不同的代码#s。

(Get-NlbClusterNode -HostName BN1WUSSQL6LA331).state   
于 2015-11-19T23:31:43.700 回答