VMware Cloud Community
ramseyd
Contributor
Contributor

Script to delete one VM affinity rule per cluster in vCenter

Trying to delete just one VM to host affinity rule in all clusters in all datacenters in one vCenter.

Here is what i have so far but its not working

ForEach($dc in Get-Datacenter){$dc | Get-Cluster) If (DrsRule -Name eq  "Rule 1 VMs to Host") Then DrsRule.Enabled = False Else Do Nothing}

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

You can't change a property like that on an object.

Again have a look at the DRSRule module as I mentioned in Re: PowerCLI script to disable vm affinity rules


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

Reply
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

Reply
0 Kudos