VMware Cloud Community
ramseyd
Contributor
Contributor

PowerCLI script to disable vm affinity rules

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?

0 Kudos
3 Replies
LucD
Leadership
Leadership

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
heng_arc
Contributor
Contributor

Get-Drsrule -Cluster $ClusterName | Set-DrsRule -Enabled $false

0 Kudos