使用以下代码我能够将 ISO 安装到虚拟机的 CD 驱动器并更改虚拟机的 BootOrder
$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)`
BootOrder 的输出
BootDelay : 0
EnterBIOSSetup : False
EfiSecureBootEnabled : False
BootRetryEnabled : False
BootRetryDelay : 10000
BootOrder : {VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice, 4000, 2000}
NetworkBootProtocol : ipv4
参考@Gerald Schneider 的回答:通过 PowerCLI 设置 VM 启动 CD
上述代码运行良好,但是当我重新启动虚拟机时,它并没有启动启动过程。
请让我知道我在这里遗漏了什么