Automation

 View Only
  • 1.  Deploy multiple VMs to multiple hosts evenly?

    Posted Jun 20, 2016 11:32 AM

    Hello folks!

    I've written a short script to deploy multiple VMs to multiple hosts randomly.

    But I would rather deploy a VM to each host in an array and then start from the beginning again until number of VMs to deploy runs out.  Spreading the deployment load as evenly as possible.

    Would anyone have a suggestion?  Nested loop example?

    Powershell beginner, here.  :smileyhappy:

    Thanks,

    romatlo



  • 2.  RE: Deploy multiple VMs to multiple hosts evenly?
    Best Answer

    Posted Jun 20, 2016 11:57 AM

    One way of doing this is with the modulo operator (%), something like this

    $numVMs =11

    $tgtEsx = Get-Cluster 'Westcreek' | Get-VMHost -Name z420*

    1..$numVMs | %{

        New-VM -Name "Test$($_)" -VMHost $tgtEsx[$_%$tgtEsx.Count]

    }



  • 3.  RE: Deploy multiple VMs to multiple hosts evenly?

    Posted Jun 24, 2016 05:33 PM

    Thank you for the feedback!

    I ended up finding a solution based on your feedback and others.

    Here is the script I ended up with that is working well so far for what I need it for immediately.

    Thanks again!

    $VMHOSTS = Get-Cluster 'Westcreek' | Get-VMHOST | Sort name

    $NumVMs = 3

    $NEW_VMS = (1..$NumVMs)

    $myTemplate = Get-Template -Name Win7temp

    $mySpecification = Get-OSCustomizationSpec -Name win7

    $i = 0

    ForEach ($VM in $NEW_VMS) {

    New-VM -Name test$($VM) -VMHost $($VMHOSTS[$i]) -ResourcePool Hosts -Template $myTemplate -OSCustomizationSpec $mySpecification -Datastore VMs2 -DiskStorageFormat Thin

    $i++

    If ($i -ge $VMHOSTS.count) {$i=0}

    }



  • 4.  RE: Deploy multiple VMs to multiple hosts evenly?

    Posted Jun 24, 2016 05:43 PM

    Great job figuring out your solution.  On the flip-side.  Assuming DRS is running and set to automatic, DRS will power-on the newly deployed VM's in a distributed fashion.  Meaning you could deploy all VM's to one host in the cluster and be fine since DRS would distribute them evenly for you.