Automation

 View Only
  • 1.  can you automate affinity rules

    Posted Sep 20, 2023 12:41 PM

    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.



  • 2.  RE: can you automate affinity rules

    Posted Sep 20, 2023 01:31 PM

    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;

     



  • 3.  RE: can you automate affinity rules

    Posted Sep 21, 2023 07:44 AM

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

     



  • 4.  RE: can you automate affinity rules

    Posted Sep 21, 2023 07:48 AM

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



  • 5.  RE: can you automate affinity rules

    Posted Sep 21, 2023 07:54 AM

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

    Sorry i dont have much experience with powercli scripts



  • 6.  RE: can you automate affinity rules

    Posted Sep 21, 2023 08:18 AM

    task scheduler in win.

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