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 |
Did you run that script while the VM was powered off?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD No, the VM is powered On when I ran the script and then after execution I have restarted
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD 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
I was talking about the ReconfigVM method, not the Set-CDRom cmdlet.
One needs the VM to be powered on, the other doesn't
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Yes, I ran the ReconfigVM method in PowerOff mode. then started the VM. Still no change
And you did check that the method call ended successfully?
Did you check the bootorder before restarting the VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD 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 |
>> ... 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é
@a_p_ 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