May not be the fastest or most efficient but it was the first way that came to mind.
foreach($vm in $vms){
# Check if VM is not in a cluster at all and report
If(!(Get-Cluster -VM $vm)){
$vm | Add-Member -MemberType NoteProperty -Name Cluster -Value "None"
$vm | Add-Member -MemberType NoteProperty -Name DRSEnabled -Value "None"
$vm | Select Name, Cluster, DRSEnabled, PowerState
}Else{
# Since VM is in a cluster, check if DRS is enabled and report
$cluster = Get-Cluster -VM $vm
$vm | Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name
$vm | Add-Member -MemberType NoteProperty -Name DRSEnabled -Value $cluster.DrsEnabled
$vm | Select Name, Cluster, DRSEnabled, PowerState
}
}
Thank you for taking the time to reply.
Does this check for VM DRS Groups, or whether the VM is in a DRS enabled cluster?
Thanks
Josh's script checks if a VM is in a DRS-enabled cluster.
Try this to find VMs that are not in a DRS VM group.
$vmTab = @{} Get-VM | %{ $vmTab.Add($_.Name,$null) } Get-Cluster | %{ $_.ExtensionData.ConfigurationEx.Group | where {$_.GetType().Name -eq "ClusterVmGroup"} | %{ Get-View $_.Vm | %{ $vmTab.Remove($_.Name) } } } $vmTab.Keys
The script uses a hash table to
1) get all the VMs
2) remove the VMs that are in a DRS VM group
3) display the VM names
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ahh....It seems I misread/misunderstood the request. Once again well done Luc! Learning something new every day
This looks very good.
To test properly, how would I specify a specific cluster to check?
Thanks
Something like this
$vmTab = @{} Get-Cluster -Name MyCLuster | Get-VM | %{ $vmTab.Add($_.Name,$null) } Get-Cluster -Name MyCluster | %{ $_.ExtensionData.ConfigurationEx.Group | where {$_.GetType().Name -eq "ClusterVmGroup"} | %{ Get-View $_.Vm | %{ $vmTab.Remove($_.Name) } } } $vmTab.Keys
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That’s not returning any results unfortunately.
That could mean that all the VMs in that cluster are in a DRS group.
Try running this version, it will first display all the VMs that are found on the cluster.
$vmTab = @{} Get-Cluster -Name MyCLuster | Get-VM | %{ $vmTab.Add($_.Name,$null) } "VMs in cluster"
$vmTab.Keys
Get-Cluster -Name MyCluster | %{ $_.ExtensionData.ConfigurationEx.Group | where {$_.GetType().Name -eq "ClusterVmGroup"} | %{ Get-View $_.Vm | %{ $vmTab.Remove($_.Name) } } } "VMs not in a DRS group"
$vmTab.Keys
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I removed a server from a DRS group to check, but no luck.
anyway, the first script you did is excellent and is working correclty. is there any way it could email me the results?
thank you
Try it with the Send-MailMessage cmdlet
Send-MailMessage -SmtpServer mailserver.corp.com -To me@corp.com -From report@corp.com -Subject DRS -Body $vmTab.Keys
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this works, but just lists the vms one after the other e.g.
server1 server2 server3 .......
can it be formatted like
server1
server2
server3
thanks
Change the Body parameter from
-Body $vmTab.Keys
to
-Body ($vmTab.Keys | Out-String)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's excellent, and works very well.
Thank you very much for all your help, and thanks aerodevil for taking the time to reply too.