Powershell – Setting a VM boot CD via PowerCLI

powerclipowershellpxe-bootvmware-vsphere

I have a sneaking suspicion that this may be a bug, but I'm definitely willing to entertain the possibility that I'm doing things wrong.

I have a VMware virtual machine in $vm, and I'm trying to assign a boot CD for it. $vm is powered off.

The documented method seems pretty straightforward:

Set-CDDrive -CD (Get-CDDrive -vm $vm) -IsoPath "[datastorename] \whatever.iso" -StartConnected 1

Now, when I start the VM, it immediately tries to PXEboot. I turn off the machine, and in the vSphere client, I edit the VM's properties, go to "CD/DVD drive 1", and verify, "Device Status" has a checkmark next to "Connect at power on".

Here's the crazy thing. When I uncheck that box, then check it again, then start the VM, it boots from the ISO.

I've done it again and again, with the console open, with it closed, and every time, I can set the StartConnected flag on the CLI, and the GUI reflects the setting, but only after I mark the checkbox manually does it actually boot from the ISO.

Is there a step that I'm neglecting to perform in PowerCLI to get this setting to "take"?

Best Answer

From the PowerCLI reference online, I see the following example (replace value after -ISOPath with your datastore and name/path for .iso file like so"[yourdatastore] IsoFolder\$iso"):

$cd = New-CDDrive -VM $vm -ISOPath "[sof-20666-esx:storage1] ISO\testISO.iso"
Set-CDDrive -CD $cd -StartConnected -Connected
Related Topic