VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

ESXi Build Version Check in Cluster

Hi All,

I have written below script to get Unique ESXi Host Build Version, But I am not getting any output.

$hvs = Get-VMHost  | Get-View

$cv = Get-Cluster | Get-View

foreach($hv in $hvs){

$hv | ?{$_.Parent -match $cv.MoRef} | select @{N="ESXi Node Version";E={$_.Config.Product.FullName}} -unique

}

Am I missing something in this script,Please suggest.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case the variable $cv will be an array, and $cv.MoRef will not exist.

Try like this, the ESXi nodes will belong to a cluster.

Get-Cluster | Get-VMHost |

Select @{N="ESXi Node Version";E={$_.ExtensionData.Config.Product.FullName}} -unique


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Is there perhaps more than 1 cluster in your environment ?

Does Get-Cluster return more than 1 object ?


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

We have 6+ Clusters and get-cluster cmdlet is returning all the cluster names.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case the variable $cv will be an array, and $cv.MoRef will not exist.

Try like this, the ESXi nodes will belong to a cluster.

Get-Cluster | Get-VMHost |

Select @{N="ESXi Node Version";E={$_.ExtensionData.Config.Product.FullName}} -unique


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

The below script gives me desired output. Thanks a lot.

More over is there any way that we can check ESXi Node Version in each cluster and get output if there is any mismatch otherwises it needs to print only the Unique BuildVersion(Without using foreach loop and if statement as we can't use it to print it in html output).

Please suggest.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-Cluster |

where {(Get-VMHost -Location $_ |

    Sort-Object -Property {$_.ExtensionData.Config.Product.FullName} -Unique).Count -gt 1} |

Select Name,@{N='Warning';E={'Multiple ESXi versiona present in cluster'}}


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

Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Thanks Lucd Script is working.

MoreOver it is displaying ClusterName is it possible to get Clustername along with Hostname which is mismatching.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For which ESX- node shall the name be displayed in that case ?

That would assume there is a rule to determine which ESXi version is incorrect.

Assume a cluster with 2 nodes, A and B.

They have different ESXi versions installed, which one shall be displayed as the incorrect one ?


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Assume with 3 Clusters

Cluster1 - ESXi1,ESXi2,ESXi3 - 1 & 2 are unique

Cluster2 - ESXi4,ESXi5,ESXi6 - 2 & 3 are unique

Cluster3 - ESXi7,ESXi8,ESXi9 - 3 & 1 are unique

Now Output should be

Cluster1 ESXi3

Cluster2 ESXi1

Cluster3 ESXi2

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-Cluster | %{

    $versions = Get-VMHost -Location $_ | Select Name,@{N='Version';E={$_.ExtensionData.Config.Product.FullName}} | Group-Object -Property Version

    if($version.Count -gt 1){

        $OddOneOut = $versions | Sort-Object -Property {$_.Group.Count} -Descending | Select -First 1

        $_ | Select Name,@{N='Warning';E={'Multiple ESXi version present'}},

            @{N='Wrong ESXi';E={[string]::Join(',',($OddOneOut.Group | %{$_.Name}))}}

    }

}


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

Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Thanks Lucd,

Script works fine. Thanks a lot.

0 Kudos