I have a script to list VM affinity rules for all clusters in every datastore:
ForEach ($dc
in Get-Datacenter){$dc | Get-Cluster | Get-DrsRule –type VMHostAffinity |
sort cluster
| select Name, Cluster, Enabled,
@{N=’DataCenter’;E={$dc}
}}
Is there a way to disable VM affinity rules for clusters by name? For example:
For all clusters in all datacenters in vCenter01
If -cluster.name = Cluster01,cluster02
then do nothing
else
affinityrules = remove
Above is just a rough draft of what im trying to accomplish and working on now. Any ideas?
The DRSRule module alllows you to do that with the Get-DrsVMToVMHostRule
and the Remove-DrsVMToVMHostRule
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As from the PowerCLI 6.5.2 release there are now built in cmdlets for that functionality.
See New Release: PowerCLI 6.5.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-Drsrule -Cluster $ClusterName | Set-DrsRule -Enabled $false