VMware Cloud Community
pezh0re
Enthusiast
Enthusiast

Unmount an ISO using Views and ReconfigVm_Task()

I know it's possible to unmount an ISO using the PowerCLI Cmdlets:

Get-VM | Get-CDDrive | Where { $_.IsoPath } | Set-CDDrive -NoMedia -Confirm:$false

But I'm curious if the same thing can be done via the ReconfigVm_Task($Config) capability of a VirtualMachine View. I'm potentially changing several settings in this validation script (CPU/Memory Reservation/Limit/Shares, BootDelay, etc) - all captured as one large VMware.Vim.VirtualMachineConfigSpec. At the end of my validation script, I'm issuing one single Reconfigure task to speed up the process - rather than doing individual reconfigures.

Is it possible to unmount an ISO using only Get-View, manipulating a VirtualMachineConfigSpec, and ReconfigVm_Task()?

I'm running this against vSphere 6.5 with PowerShell 5.1 and the latest PowerCLI module from PSGallery.

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this.
For the same code, I took the 1st CD drive, but you can pick all of them in a loop as well.

$vmName = 'MyVM'


$vm = Get-VM -Name $vmName

$dev = $vm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq "CD/DVD drive 1"}


$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "edit"

$spec.deviceChange[0].device = $dev

$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo

$spec.deviceChange[0].device.backing.DeviceName = ""

$spec.deviceChange[0].device.backing.exclusive = $false

$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$spec.deviceChange[0].device.connectable.allowGuestControl = $true

$spec.deviceChange[0].device.connectable.connected = $false

$spec.deviceChange[0].device.connectable.startConnected = $false

$spec.deviceChange[0].device.connectable.status = "ok"


$vm.ExtensionData.ReconfigVM_Task($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos