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)