Mass Editing VM Boot Delays

One of my customers offers a hosting solution.  One of their larger customers came to them with a request recently - they wanted a 5 second boot delay on all of their VMs.  This customer had previously run all of their VMs in their own vCenter and needed a way to get access to the VMs' BIOS settings now that they had the vCloud Director subset of actions.  A boot delay was deemed the best solution.  This presented another excellent scripting opportunity - a very simple task that needed to be repeated hundreds of times.

My customer was understandably hesitant to let a script just run rampant through their vCenter, and so I put together the following.  It only targets VMs in the named Resource Pool and can be further filtered by passing it a VM's name (or part of a name) with the -VM parameter.  After that, it loops through the list of all returned VMs and checks their boot delay setting.  If the VM doesn't have the correct Boot Delay, the script prompts the user and changes it if the user gives permission.  Nice and easy and wow, what a time saver.

As always, this is being posted for educational purposes and is offered with no guarantee, use at your own risk... yadda, yadda, yadda.  It worked for me in this particular situation, but please look over the code and make sure that it's not going to do anything unexpected in your environment.

#Sets the boot delay to 5000 ms for each VM in the DPR cluster
#Based on Keith Luken's vmbootdelay.ps1 script
#Modification by Jason Coleman 11/10/2014

    [int]$bootDelay = 5000,
    [string]$ResourcePool = "customer-name",
    [string]$VM = "*"

#Gets all specified VMs from the appropriate resource pool
$vms = Get-ResourcePool -name $ResourcePool | Get-VM $VM

#Creates the VM config spec object with the specified ms boot delay
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
$vmbo.BootDelay = $bootDelay
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcs.BootOptions = $vmbo

#Sets the boot delay for all VMs that do not currently have it, prompting the user for confirmation for each VM.
foreach ($thisVM in $vms)
    if ($thisvm.ExtensionData.config.BootOptions.BootDelay -ne $bootDelay)
      [string]$response = Read-Host "Reconfigure $thisVM to have a $bootDelay ms boot delay (Y|N)?"
        switch -wildcard ($response)
            "y*" {$thisVM.ExtensionData.ReconfigVM($vmcs)}
            "n*" {echo "skipping $thisVM"}
            default {echo "unexpected input, skipping $thisVM"}


Popular posts from this blog

vCenter Server Appliance Crash due to Full /Storage/SEAT Partition

Deleting Orphaned (AKA Zombie) VMDK Files

PowerShell Sorting by Multiple Columns