VMware Cloud Community
jojo130374
Enthusiast
Enthusiast

Looking for a script to check if VM is in groups

Hello

We have 2 groups on each DRS Clusters. We have several clusters and DRS goups name is the same on each cluster

VM have to be in one of the following groups, we need the script to check this :

VM_GROUP_1 or VM_GROUP_2

VM are also in a third group (VM_ALL), but this group has not be check in the script (exception)

Could you please help us ?

Thanks

Regards

 

 

 

 

 

 

0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this

$groups = 'VM_GROUP_1','VM_GROUP_2'

Get-cluster -PipelineVariable cluster |
ForEach-Object -Process {
    $hashTable = @{}

    Get-VM -Location $cluster |
    ForEach-Object -Process {
        $hashTable.Add($_.Name,'')
    }
    
    $groups | ForEach-Object -Process {
        (Get-DrsClusterGroup -Name $_ -Cluster $cluster).Member |
        ForEach-Object -Process {
            $hashTable.Remove($_.Name)
        }
    }
    
    Write-Host "Following VMs are not in any of the DRS groups on cluster $($cluster.Name)"
    $hashTable.GetEnumerator().Name
}


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