VMware Cloud Community
rellan1
Contributor
Contributor
Jump to solution

Powercli script host cluster

I'm working on a PowerCLI script that will call an ESXi host and identify whether or not it is in a vCenter cluster.  

These ESXi hosts may or may not be in a vCenter cluster, part of this script is also to validate access.

What is the powercli expression I would use to identify if an ESXi host is in a cluster or not?  Can you provide an example?

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Then that is a bit of a chicken-and-the-egg issue, a cluster is a vCenter concept.
When you connect to an ESXi node, you can see if that ESXi node is managed by a vCenter or not.

Get-VMHost |
Select Name,@{N='vCenter';E={$_.ExtensionData.Summary.ManagementServerIP}}


But you can't really query if in the vCenter that ESXi node is part of a cluster in that vCenter.

You could eventually check if processes like HA Agent are running on the ESXi node.
But that would not be foolproof since HA can be disabled.

To check if the fdm process is running, you could do

Get-VMHost |
Select Name ,
  @{N='HA Agent'; E={
    $esxcli = Get-EsxCli -VMHost $_ -V2
    if($esxcli.system.process.list.Invoke().Where{$_.Name -match "^fdm$"} -ne $null){$true}else{$false}
  }}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

Is there a question in here?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership
Jump to solution

You could do

Get-VMHost |
Select Name,@{N='Incluster';E={(Get-Cluster -VMHost $_) -ne $null}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

rellan1
Contributor
Contributor
Jump to solution

LucD,

Thanks for the quick response. 

 

I get the same return value for each one. The first host I know is in a cluster, but it returns a "False" value.  The second host I tried is not in a cluster and returns the same "False" value.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you connected to a vCenter? Or ESXi nodes?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
rellan1
Contributor
Contributor
Jump to solution

ESXi Nodes only.  Your script gives me the information I'm looking for.  I'll sort the spreadsheet when I include the vCenter clusters.  

Thanks a bunch LucD!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then that is a bit of a chicken-and-the-egg issue, a cluster is a vCenter concept.
When you connect to an ESXi node, you can see if that ESXi node is managed by a vCenter or not.

Get-VMHost |
Select Name,@{N='vCenter';E={$_.ExtensionData.Summary.ManagementServerIP}}


But you can't really query if in the vCenter that ESXi node is part of a cluster in that vCenter.

You could eventually check if processes like HA Agent are running on the ESXi node.
But that would not be foolproof since HA can be disabled.

To check if the fdm process is running, you could do

Get-VMHost |
Select Name ,
  @{N='HA Agent'; E={
    $esxcli = Get-EsxCli -VMHost $_ -V2
    if($esxcli.system.process.list.Invoke().Where{$_.Name -match "^fdm$"} -ne $null){$true}else{$false}
  }}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference