Sunshine_S
Enthusiast
Enthusiast

Set CD-ROM Device mode to passthrough for all VMs

Jump to solution

To enable cloud-init, we need to modify the CD/DVD Drive 1 settings and change it to "Client Device" with device mode set to "Passthrough CD-ROM" for all our templates. I have converted all templates to VMs using PowerCLI but I am not able find an option in Set-CDDrive cmdlet for changing the device mode.

I referred these two pages along with other results in Google search:

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/cd82421a-ee01-40a9-97c3-424ae49db692/972fed92...

https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/categories/cd/

 

Cannot find anything to enable passthrough cd-rom.

I captured the code to do this manually using GUI and it gave the following result which is difficult for me to understand and execute as a script on multiple VMs.

 

#----------------- Start of code capture -----------------

#---------------EnvironmentBrowser---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.EnvironmentBrowser

#---------------Config---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.Config

#---------------QueryConfigOptionEx---------------
$spec = New-Object VMware.Vim.EnvironmentBrowserConfigOptionQuerySpec
$spec.GuestId = New-Object String[] (1)
$spec.GuestId[0] = 'windows9Server64Guest'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionEx($spec)

#---------------DatastoreBrowser---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.DatastoreBrowser

#---------------QueryTargetCapabilities---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryTargetCapabilities($null)

#---------------QueryConfigOptionDescriptor---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionDescriptor()

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ReconfigVM_Task---------------
$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].Device = New-Object VMware.Vim.VirtualCdrom
$spec.DeviceChange[0].Device.Backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$spec.DeviceChange[0].Device.Backing.Exclusive = $false
$spec.DeviceChange[0].Device.Backing.DeviceName = ''
$spec.DeviceChange[0].Device.ControllerKey = 15000
$spec.DeviceChange[0].Device.UnitNumber = 0
$spec.DeviceChange[0].Device.DeviceInfo = New-Object VMware.Vim.Description
$spec.DeviceChange[0].Device.DeviceInfo.Summary = 'ISO [Datastore] en_windows_server_2019_updated_july_2020_x64_dvd_94453821.iso'
$spec.DeviceChange[0].Device.DeviceInfo.Label = 'CD/DVD drive 1'
$spec.DeviceChange[0].Device.Key = 16000
$spec.DeviceChange[0].Operation = 'edit'
$spec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[] (0)
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.ReconfigVM_Task($spec)


#----------------- End of code capture -----------------

 

Can someone please help me in automating this task?

Labels (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this


@Sunshine_S wrote:

To enable cloud-init, we need to modify the CD/DVD Drive 1 settings and change it to "Client Device" with device mode set to "Passthrough CD-ROM" for all our templates. I have converted all templates to VMs using PowerCLI but I am not able find an option in Set-CDDrive cmdlet for changing the device mode.

I referred these two pages along with other results in Google search:

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/cd82421a-ee01-40a9-97c3-424ae49db692/972fed92...

https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/categories/cd/

 

Cannot find anything to enable passthrough cd-rom.

I captured the code to do this manually using GUI and it gave the following result which is difficult for me to understand and execute as a script on multiple VMs.

 

#----------------- Start of code capture -----------------

#---------------EnvironmentBrowser---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.EnvironmentBrowser

#---------------Config---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.Config

#---------------QueryConfigOptionEx---------------
$spec = New-Object VMware.Vim.EnvironmentBrowserConfigOptionQuerySpec
$spec.GuestId = New-Object String[] (1)
$spec.GuestId[0] = 'windows9Server64Guest'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionEx($spec)

#---------------DatastoreBrowser---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.DatastoreBrowser

#---------------QueryTargetCapabilities---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryTargetCapabilities($null)

#---------------QueryConfigOptionDescriptor---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionDescriptor()

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ReconfigVM_Task---------------
$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].Device = New-Object VMware.Vim.VirtualCdrom
$spec.DeviceChange[0].Device.Backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$spec.DeviceChange[0].Device.Backing.Exclusive = $false
$spec.DeviceChange[0].Device.Backing.DeviceName = ''
$spec.DeviceChange[0].Device.ControllerKey = 15000
$spec.DeviceChange[0].Device.UnitNumber = 0
$spec.DeviceChange[0].Device.DeviceInfo = New-Object VMware.Vim.Description
$spec.DeviceChange[0].Device.DeviceInfo.Summary = 'ISO [Datastore] en_windows_server_2019_updated_july_2020_x64_dvd_94453821.iso'
$spec.DeviceChange[0].Device.DeviceInfo.Label = 'CD/DVD drive 1'
$spec.DeviceChange[0].Device.Key = 16000
$spec.DeviceChange[0].Operation = 'edit'
$spec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[] (0)
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.ReconfigVM_Task($spec)


#----------------- End of code capture -----------------

 

Can someone please help me in automating this task?


$vm = Get-VM -Name 'MyVM'
$cd = Get-CDDrive -VM $vm -Name 'CD/DVD drive 1'

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev =  New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Operation = 'edit'
$dev.Device = $cd.ExtensionData
$dev.Device.Backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$dev.Device.Backing.Exclusive = $false
$dev.Device.Backing.DeviceName = ''

$spec.DeviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)


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

View solution in original post

5 Replies
LucD
Leadership
Leadership

Try something like this


@Sunshine_S wrote:

To enable cloud-init, we need to modify the CD/DVD Drive 1 settings and change it to "Client Device" with device mode set to "Passthrough CD-ROM" for all our templates. I have converted all templates to VMs using PowerCLI but I am not able find an option in Set-CDDrive cmdlet for changing the device mode.

I referred these two pages along with other results in Google search:

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/cd82421a-ee01-40a9-97c3-424ae49db692/972fed92...

https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/categories/cd/

 

Cannot find anything to enable passthrough cd-rom.

I captured the code to do this manually using GUI and it gave the following result which is difficult for me to understand and execute as a script on multiple VMs.

 

#----------------- Start of code capture -----------------

#---------------EnvironmentBrowser---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.EnvironmentBrowser

#---------------Config---------------
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.Config

#---------------QueryConfigOptionEx---------------
$spec = New-Object VMware.Vim.EnvironmentBrowserConfigOptionQuerySpec
$spec.GuestId = New-Object String[] (1)
$spec.GuestId[0] = 'windows9Server64Guest'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionEx($spec)

#---------------DatastoreBrowser---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.DatastoreBrowser

#---------------QueryTargetCapabilities---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryTargetCapabilities($null)

#---------------QueryConfigOptionDescriptor---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-111504'
$_this.QueryConfigOptionDescriptor()

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)

#---------------ReconfigVM_Task---------------
$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].Device = New-Object VMware.Vim.VirtualCdrom
$spec.DeviceChange[0].Device.Backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$spec.DeviceChange[0].Device.Backing.Exclusive = $false
$spec.DeviceChange[0].Device.Backing.DeviceName = ''
$spec.DeviceChange[0].Device.ControllerKey = 15000
$spec.DeviceChange[0].Device.UnitNumber = 0
$spec.DeviceChange[0].Device.DeviceInfo = New-Object VMware.Vim.Description
$spec.DeviceChange[0].Device.DeviceInfo.Summary = 'ISO [Datastore] en_windows_server_2019_updated_july_2020_x64_dvd_94453821.iso'
$spec.DeviceChange[0].Device.DeviceInfo.Label = 'CD/DVD drive 1'
$spec.DeviceChange[0].Device.Key = 16000
$spec.DeviceChange[0].Operation = 'edit'
$spec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[] (0)
$_this = Get-View -Id 'VirtualMachine-vm-111504'
$_this.ReconfigVM_Task($spec)


#----------------- End of code capture -----------------

 

Can someone please help me in automating this task?


$vm = Get-VM -Name 'MyVM'
$cd = Get-CDDrive -VM $vm -Name 'CD/DVD drive 1'

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev =  New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Operation = 'edit'
$dev.Device = $cd.ExtensionData
$dev.Device.Backing = New-Object VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$dev.Device.Backing.Exclusive = $false
$dev.Device.Backing.DeviceName = ''

$spec.DeviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)


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

Sunshine_S
Enthusiast
Enthusiast

Thanks LucD,

It worked for all VMs where the CD drive was set to client device. For these VMs the device mode got changed from emulated to passthrough successfully. But the VMs that were having a Datastore iso connected were not updated. Got an error for those VMs. Can you please suggest what I need to add or change in the script to correct this?

0 Kudos
LucD
Leadership
Leadership

What was the error you got?


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

0 Kudos
Sunshine_S
Enthusiast
Enthusiast

Error:

 

Exception calling "ReconfigVM" with "1" argument(s): "Connection control operation failed for disk 'sata0:0'. Connection control operation failed for disk 'sata0:0'."
At C:\Users\xxx\change_cd.ps1:11 char:1
+ $vm.ExtensionData.ReconfigVM($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

0 Kudos
LucD
Leadership
Leadership

Is that VM powered on and is the CD locked by the Guest OS?
In fact, that will cause the same error when trying to do it from the Web Client (but you will get the question "The guest operating system has locked the CD-ROM door ..." in that case).

You will have to power off the VM, and then the snippet will work.


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

Tags (1)