Automation

 View Only
  • 1.  Unmount an ISO using Views and ReconfigVm_Task()

    Posted May 04, 2018 06:58 PM

    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.



  • 2.  RE: Unmount an ISO using Views and ReconfigVm_Task()

    Posted May 04, 2018 09:04 PM

    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)