Automation

 View Only
  • 1.  Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 12:03 AM

    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?



  • 2.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 12:07 AM

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



  • 3.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 12:28 AM

    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



  • 4.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 07:22 AM

    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)$'}


  • 5.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 11:00 AM

    Hi Luc,

    Can HostSystem properties be pulled from the ClusterComputeResource ViewType?

    Thanks,

    Fin



  • 6.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 11:05 AM

    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)?



  • 7.  RE: Filter Cluster Hosts from Get-View Using Cluster Wildcard

    Posted Feb 13, 2019 11:07 AM

    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

    }