ISO not booting using powwershell

43 views Asked by At

I am having the below codes where first I am mounting the ISO file to the CD drive of the VM and next I am changing the BootOrder of the VM

Mounting to CDDrive

$CloneVM = Get-VM -Name "999_SW999OSTest_Clone"
$IsoPath = "[STG5_DISTR_HPERF_DARY_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

Changing Boot Order

#Connect-VIServer -Server 12.8.1.13

$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)

Output for boot order

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

1

There are 1 answers

1
AALV8 On

If you are using VMWARE with vmware tools to capture the mouse,files,etc it uses the cd drive maybe it still have the tools on a cache and when u restart the vm it reconfigures itself to be the 1st device to boot?