VMware Cloud Community
faherne_CTI
Enthusiast
Enthusiast

Filter Cluster Hosts from Get-View Using Cluster Wildcard

We run a daily script checking the configuration and status of ESXi hosts on multiple vCenters (>100) using the following:

Foreach ($vC in $vCList){

$ESXiHosts = Get-View -viewtype hostsystem -property Name,OverallStatus,Summary,AlarmActionsEnabled,Config,TriggeredAlarm,VM,ConfigIssue | Sort-Object Name

}

Does anyone know how to modify the above Get-View command so that it filters out the ESXi hosts in clusters matching the *Build cluster wildcard?

0 Kudos
6 Replies
faherne_CTI
Enthusiast
Enthusiast

As there are so many vCenters, clusters and ESXi hosts involved, speed is the most important factor I'm looking for in the script.

0 Kudos
faherne_CTI
Enthusiast
Enthusiast

I tied the following, but keep getting errors:

1.)

Get-Cluster | ? {$_.Name -NotLike "*Build"} | Get-VMHost | Get-View

2.)

$FilteredESXiHostList = Get-Cluster | ? {$_.Name -NotLike "*Build"} | Get-VMHost

Get-VMHost $FilteredESXiHostList | Get-View

0 Kudos
LucD
Leadership
Leadership

With a RegEX expression that uses negative lookbehind, you can filter out all clusters with a name that ends in 'Build'

Get-View -ViewType ClusterComputeResource -Filter @{'Name' = '.*(?<!Build)$'}


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

0 Kudos
faherne_CTI
Enthusiast
Enthusiast

Hi Luc,

Can HostSystem properties be pulled from the ClusterComputeResource ViewType?

Thanks,

Fin

0 Kudos
faherne_CTI
Enthusiast
Enthusiast

Or could the Get-View HostSystem ViewType be filtered using RegEx against the Parent (making assumption that the parent of HostSystem is it's Cluster)?

0 Kudos
LucD
Leadership
Leadership

Yes, there is a Host property, containing the MoRef to the ESXi nodes in the cluster.

Get-View -ViewType ClusterComputeResource -Property Name,Host -PipelineVariable cluster |

ForEach-Object -Process {

   Get-View -Id $_.Host |

  Select @{N='Cluster';E={$cluster.Name}},Name

}


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

0 Kudos