Force a VM to enter BIOS setup screen on next reboot

August 27, 2009

2 comments

With the following PowerCLI filter you can force entry of virtual machine(s) into the BIOS setup screen next time the VM boots. You can configure the option in the VM options tab but with Set-VMBIOSSetup you can toggle the value programmatically:



Note that setting a VM to enter BIOS mode is a one time action. Once the VM reboots and enters the BIOS screen the ‘Force BIOS Setup’ flag is unchecked so that subsequent boots proceed normally.



filter Set-VMBIOSSetup
{
  
param(
        [
switch]$Disable,
        [
switch]$PassThru
   )

   if($_ -is [VMware.VimAutomation.Types.VirtualMachine])
    {
      
trap { throw $_ }       
       
      
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
      
$vmbo.EnterBIOSSetup = $true
       
      
if($Disable)
        {
          
$vmbo.EnterBIOSSetup = $false
        }

      
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
      
$vmcs.BootOptions = $vmbo

        (
$_ | Get-View).ReconfigVM($vmcs)
       
      
if($PassThru)
        {
          
Get-VM $_
        }
    }
  
else
    {
      
Write-Error Wrong object type. Only virtual machine objects are allowed.
    }
}



Sample usage:


## Get all VMs which name starts with XP, force the VM to enter into bios
## mode on next boot and write VM objects back to pipeline

Get-VM XP* | Set-VMBIOSSetup -PassThru

# Get all VMs which name starts with XP and disable (uncheck) bios mode on next boot
Get-VM XP* | Set-VMBIOSSetup -Disable



One thing I found when testing the filter on ESXi 4 is that you get an error ‘fault.RestrictedVersion.summary’ if ESXi is registered, surprisingly it works if ESXi 4 is not registered. Duh!



 

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

2 comments

  1. Wil van AntwerpenAugust 28, 2009 ב 20:18

    Nice script!

    If it doesn’t work for ESXi 4 then you are likely using the free version which is restricted in several ways when trying to write out settings using powerCLI.
    When you switch to -for example- a standard license, it will work without throwing the restricted version error.

    Wil

    Reply
  2. ScriptFanaticAugust 29, 2009 ב 16:10

    Thanks Wil.

    Well, it depends on what you call a ‘standard license’. I have a valid license key. After I register the product the ‘Product’ column shows: “ESXi 4 Single Server (1-6 cores per CPU)” and the ‘Avaiable’ column shows: Unlimited. In the bottom of the dialog I can also see ‘(Expires: Never)’.

    Reply