VMware Cloud Community
DusanJanak
Contributor
Contributor

can you automate affinity rules

Hey guys,

I wanted to ask if there is a way to automate adding newly created VMs to affinity rule that blocks them from one of the hosts in the cluster?

I have seen a post from 2012 but there was no solution.

Thanks for the replies.

Reply
0 Kudos
5 Replies
MerlevedeN
Enthusiast
Enthusiast

With powercli: 

$vm = Get-VM DrsRuleVM1*
$myCluster = Get-Cluster -Name "MyCluster1" $affinityRule = Get-DrsRule -Cluster $myCluster -Name "*Rule1*"
Set-DrsRule -Rule $affinityRule -VM $vm -Enabled $true;

 

Reply
0 Kudos
DusanJanak
Contributor
Contributor

Thank you, that works. But is there any way to automate it f.e. every other week?

 

Reply
0 Kudos
MerlevedeN
Enthusiast
Enthusiast

Yes, you can add it to a scheduled task. Or add it at the end of you VM deployment procedure.

Reply
0 Kudos
DusanJanak
Contributor
Contributor

Do you mean scheduled tasks in vCenter or just in task scheduler in win?

Sorry i dont have much experience with powercli scripts

Reply
0 Kudos
MerlevedeN
Enthusiast
Enthusiast

task scheduler in win.

PowerCLI is just a collection of PowerShell modules to manage VMware product. 

Reply
0 Kudos