locked
How can I configure all VMs to use a different startup delay, let´s say, one VM every minute? RRS feed

  • Question

  • How to configure the AutomaticStartAction for VMs in Hyper-V - Setting every VM to a different startup delay?

    I have several VMs, on a cluster, how can I configure all VMs to use a different startup delay, let´s say, one VM every minute?

    The idea here, is to list all VMs and configure a startup delay of 0 for the first, 60 seconds for the second, 120 seconds for the thrid and so on, progressvly raising the startup delay for every VM?

    i started with a small script i found in the net, but it uses a fixed list of machines, the ideal is to list the machines in the cluster, dynamically, to make sure new and old Vms are added or removed form the script

    but i would like to run from time to time, a script, to make sure that even new VMs added to the system will have its configuration based on a "schedule" of boot delay

    Obviously, i´m not taking nito account, priorities, like, how to boot ActiveDirectory first, but a simple script maybe could do the job

    http://www.altaro.com/hyper-v/how-to-configure-vm-auto-start-powershell/

    $hosts = @{ComputerName = "SRV1","SRV2" }
    Get-VM @hosts –vmname * | Select-Object VMname,AutomaticStartAction,AutomaticStartDelay


    • Edited by KayZerSoze Friday, July 17, 2015 3:07 PM typo error
    Friday, July 17, 2015 3:06 PM

Answers

  • Untested:

    $delay = 0
    Get-ClusterGroup | ? {$_.GroupType -eq 'VirtualMachine' } | Get-VM | % {
        Set-VM -Name $_.Name -AutomaticStartDelay $delay 
        $delay += 60
    }



    Friday, July 17, 2015 6:04 PM

All replies

  • The system handles all of that for you.  Delaying is so some system will be fully up before other attempt to come online.

    Have you looked at the CmdLets for managing VMs?

    Start with HELP Set-VM -Full


    \_(ツ)_/

    Friday, July 17, 2015 3:31 PM
  • Yes, na as far as i know, there are only 2 parameters:

     - delay or not

    - how many seconds to delay

    https://technet.microsoft.com/en-us/library/hh848575(v=wps.630).aspx

    there´s no such thing, as "...wait untill previous VM to be available to start the next reboot..."

    Friday, July 17, 2015 4:53 PM
  • Kaiser Soze does not exist.

    That said ...  ther eis no wait to wait.  The delay is so you can set a delay for that purpose. 

    Start by reading the help I posted.


    \_(ツ)_/

    Friday, July 17, 2015 5:04 PM
  •  -AutomaticStartDelay <Int32>
         Specifies the number of seconds by which the virtual machine's start should be delayed.

         Required?                    false
         Position?                    named
         Default value
         Accept pipeline input?       false
         Accept wildcard characters?  false


    \_(ツ)_/

    Friday, July 17, 2015 5:05 PM
  • Ok, but i think i was not clear enough:

    How can i create a Script to set it AUOMATICALLY, for ALL VMs (even in a Cluster), so, ALL VMs, will be configured to delas, from 0 seconds, 60, seconds, 120 seconds and so on, AUOMATICALLY FOR ALL VMs, listing ALL VMs and setting the so famous parameter cycling throug ALL existing VMs, no needing to type VMs names, delays.. just pressing ENTER... so.. a scipt

    (-:

    "..

    The idea here, is to list all VMs and configure a startup delay of 0 for the first, 60 seconds for the second, 120 seconds for the thrid and so on, progressvly raising the startup delay for every VM?

    ..."

    In my head, the code:

    1) List all VM anmes of the CLUSTER

    2) set delay for VM#1 to 60 seconds

    3) set delay for VM#2 to 120 seconds

    4) set delay for VM#3 to 180 seconds

    5) set delay for VM#4 to 240 seconds

    and so on

    Friday, July 17, 2015 5:39 PM
  • Untested:

    $delay = 0
    Get-ClusterGroup | ? {$_.GroupType -eq 'VirtualMachine' } | Get-VM | % {
        Set-VM -Name $_.Name -AutomaticStartDelay $delay 
        $delay += 60
    }



    Friday, July 17, 2015 6:04 PM
  • Part of the problem, i´ve solved:

    Get-VM–ComputerName(Get-ClusterNode–ClusterHV-cluster-02) |where{ $_.IsClustered –eq$true|Set-VM-AutomaticStartActionstart-AutomaticStartDelay60

    This, can set the SAME delay for all VMs, but i need to set for each VM, a diferente delay time, 0, 60, 120, 180, 240

    Source:

    http://www.altaro.com/hyper-v/powershell-script-hyper-v-get-clustervm/

    I´m trying to "integrate" both pieces of code:

    $StartUpInterval=60


    For

    (;$StartUpInterval-le900; )

    {

    "`$StartUpInterval is equal to $StartUpInterval"


    $StartUpInterval=$StartUpInterval+60


    }

    • Edited by KayZerSoze Friday, July 17, 2015 6:31 PM typo error
    Friday, July 17, 2015 6:09 PM
  • Is this what you are asking?


    $list = "a","b","c","d","e"
    $delay = 60
    foreach ( $item in $list ) {
      "Delay for $item = $delay"
      $delay += 60
    }
    


    -- Bill Stewart [Bill_Stewart]

    Friday, July 17, 2015 6:23 PM
  • It looks like Leif-Arne has the basics of what you appear to be asking for.

    . : | : . : | : . tim

    Friday, July 17, 2015 8:30 PM
  • Didn´t work!

    maybe because i´m running the script in one of the nodes, and the Vms are in other nodes.

    all set commands returned an error:

    "Set-VM : A parameter is invalid. Hyper-V was unable to find a virtual machine with name <<VM NAME>>"

    The Get-ClusterGroup | ? {$_.GroupType -eq 'VirtualMachine' } | Get-VM works fine

    running as admin with full cluster privileges

    Thursday, July 23, 2015 10:55 AM
  • Sorry, I just noticed a typo in my other post. 

     Set-VM –Name


    Should be:

     Set-VM -Name


    Notice dash instead of hyphen before Name.

    Edit: Also had a dash before eq.

    I have fixed the original post.

    Thursday, July 23, 2015 12:19 PM