Automation

 View Only
  • 1.  ISO not booting using powwercli

    Posted Aug 18, 2023 11:20 AM

    Hi All,

    Using below codes I am able to mount ISO to the CD drive of a VM and change the BootOrder of the VM

    $CloneVM = Get-VM -Name "999_SW999OSTest_Clone"
    $IsoPath = "[NPROD_LUN-01_DEV_3333] Patches/SW_DVD9_Win_Server_STD_CORE_2019_1809.2_64Bit_English_DC_STD_MLF_X22-18452.ISO"
    
            $CDDrive = Get-CDDrive -VM $CloneVM
            $CDDrive | Set-CDDrive -ISOPath $IsoPath -Confirm:$false -StartConnected:$true
    $strVMName = "999_SW999OSTest_Clone"
    $strBootNICDeviceName = "Network adapter 1"
    $strBootHDiskDeviceName = "Hard disk 1"
    $vm = Get-VM $strVMName
    
    $intNICDeviceKey = ($vm.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $strBootNICDeviceName}).Key
    $oBootableNIC = New-Object -TypeName VMware.Vim.VirtualMachineBootOptionsBootableEthernetDevice -Property @{"DeviceKey" = $intNICDeviceKey}
    
    $intHDiskDeviceKey = ($vm.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $strBootHDiskDeviceName}).Key
    $oBootableHDisk = New-Object -TypeName VMware.Vim.VirtualMachineBootOptionsBootableDiskDevice -Property @{"DeviceKey" = $intHDiskDeviceKey}
    $oBootableCDRom = New-Object -Type VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
    
    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{
        "BootOptions" = New-Object VMware.Vim.VirtualMachineBootOptions -Property @{
            BootOrder = $oBootableCDRom, $oBootableNIC, $oBootableHDisk
        }
    }
    $vm.ExtensionData.ReconfigVM_Task($spec)
    BootDelay            : 0
    EnterBIOSSetup       : False
    EfiSecureBootEnabled : False
    BootRetryEnabled     : False
    BootRetryDelay       : 10000
    BootOrder            : {VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice, 4000, 2000}
    NetworkBootProtocol  : ipv4

    The above code is working fine, but when I restarted the VM, it is not starting the boot process.

    Please let me know what I am missing here



  • 2.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 11:31 AM

    Did you run that script while the VM was powered off?



  • 3.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 11:37 AM

     No, the VM is powered On when I ran the script and then after execution I have restarted



  • 4.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 11:48 AM

    When you power off the VM the current settings are saved, overwriting what your script changed.

    Try running the script with the VM powered off



  • 5.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 12:16 PM

     I tried the code by turning the VM off. for mounting I got the error "Set-CDDrive The VM must be in the following state: PoweredOn."

    still as the ISO was already mounted, I started the VM again but no change



  • 6.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 12:25 PM

     I was talking about the ReconfigVM method, not the Set-CDRom cmdlet.
    One needs the VM to be powered on, the other doesn't



  • 7.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 12:38 PM

     Yes, I ran the ReconfigVM method in PowerOff mode. then started the VM. Still no change



  • 8.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 01:14 PM

    And you did check that the method call ended successfully?
    Did you check the bootorder before restarting the VM?



  • 9.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 01:26 PM

     Yes. I checked the bootoption. just now I executed the code again by Turning Off the VM and checked the BootOption. Looks fine

     

    BootDelay : 0
    EnterBIOSSetup : False
    EfiSecureBootEnabled : False
    BootRetryEnabled : False
    BootRetryDelay : 10000
    BootOrder : {VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice, 4000, 2000}
    NetworkBootProtocol : ipv4


  • 10.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 02:01 PM

    >> ... but when I restarted the VM, it is not starting the boot process.
    Just a quick question. Doesn't the boot process start at all from the image, or does it fall back to the disk?
    I'm asking because most current Windows images require that one hits a key to boot from the image, if there's already an OS installed on the disk.

    André



  • 11.  RE: ISO not booting using powwercli

    Posted Aug 18, 2023 02:19 PM

     The Image is already mounted in CD Drive in the server.

    Doesn't the boot process start at all from the image, or does it fall back to the disk? - I am not sure about your question. but manually if I execute the setup.exe which is there in the ISO, it prompts the GUI. from BIOS I am not sure about the boot process how it will work