I am using some code from <[http://www.lucd.info/2009/12/08/switching-to-the-paravirtual-scsi-controller/]> on vSphere 4.1. I have tried it on a number of very vanilla VMs and receive the following output when trying to convert a controller to paravirtual:
Exception calling "ReconfigVM" with "1" argument(s): "Invalid configuration for device '2'."
At line:33 char:15
+ $vm.ReconfigVM <<<< ($spec)
+ CategoryInfo : NotSpecified: ( [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Code to add and remove pvscsi controllers works fine on this VM. Does anyone have any suggestions or confirmation that this code will still work on vSphere 4.1? I can manually change the controller type in VC without issue. Thanks.
$vmName = "myvm"
$ctrlName = "SCSI controller 0"
$vm = Get-VM $vmName | Get-View
#Get the controller and the devices connected to it
$vm.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq $ctrlName} | % {
$oldCtrl = $_
$ctrlKey = $_.Key
$devs = @()
$_.Device | % {
$devKey = $_
$vm.Config.Hardware.Device | where {$_.Key -eq $devKey} | % {
$devs += $_
}
}
}
#Create the specification for the device changes
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
#Remove old controller
$old = New-Object VMware.Vim.VirtualDeviceConfigSpec
$old.device = $oldCtrl
$old.operation = "remove"
$spec.DeviceChange += $old
#Update the devices connected to the controller
$devs | % {
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.device = $_
$dev.device.ControllerKey = - 100
$dev.operation = "edit"
$spec.DeviceChange += $dev
}
#Add new controller
$new = New-Object VMware.Vim.VirtualDeviceConfigSpec
$new.Device = New-Object VMware.Vim.ParaVirtualSCSIController
$new.Device.Key = - 100
$new.operation = "add"
$spec.DeviceChange += $new
$vm.ReconfigVM($spec)
Thanks for reporting this.
vSphere 4.1 seems to require the controllerKey and unitNumber properties on the new controller as well.
Can you give the updated script below a try ?
$vmName = "MyVM" $ctrlName = "SCSI controller 0" $vm = Get-VM $vmName | Get-View # Get the controller and the devices connected to it $vm.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq $ctrlName} | % { $oldCtrl = $_ $ctrlKey = $_.Key $devs = @() $_.Device | % { $devKey = $_ $vm.Config.Hardware.Device | where {$_.Key -eq $devKey} | % { $devs += $_ } } } # Create the specification for the device changes $spec = New-Object VMware.Vim.VirtualMachineConfigSpec # Remove old controller $old = New-Object VMware.Vim.VirtualDeviceConfigSpec $old.device = $oldCtrl $old.operation = "remove" $spec.DeviceChange += $old # Update the devices connected to the controller $devs | % { $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec $dev.device = $_ $dev.device.ControllerKey = - 100 $dev.operation = "edit" $spec.DeviceChange += $dev } # Add new controller $new = New-Object VMware.Vim.VirtualDeviceConfigSpec $new.Device = New-Object VMware.Vim.ParaVirtualSCSIController $new.Device.Key = - 100 $new.Device.ControllerKey = $oldCtrl.ControllerKey $new.Device.UnitNumber = $oldCtrl.UnitNumber $new.operation = "add" $spec.DeviceChange += $new $vm.ReconfigVM($spec)
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for reporting this.
vSphere 4.1 seems to require the controllerKey and unitNumber properties on the new controller as well.
Can you give the updated script below a try ?
$vmName = "MyVM" $ctrlName = "SCSI controller 0" $vm = Get-VM $vmName | Get-View # Get the controller and the devices connected to it $vm.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq $ctrlName} | % { $oldCtrl = $_ $ctrlKey = $_.Key $devs = @() $_.Device | % { $devKey = $_ $vm.Config.Hardware.Device | where {$_.Key -eq $devKey} | % { $devs += $_ } } } # Create the specification for the device changes $spec = New-Object VMware.Vim.VirtualMachineConfigSpec # Remove old controller $old = New-Object VMware.Vim.VirtualDeviceConfigSpec $old.device = $oldCtrl $old.operation = "remove" $spec.DeviceChange += $old # Update the devices connected to the controller $devs | % { $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec $dev.device = $_ $dev.device.ControllerKey = - 100 $dev.operation = "edit" $spec.DeviceChange += $dev } # Add new controller $new = New-Object VMware.Vim.VirtualDeviceConfigSpec $new.Device = New-Object VMware.Vim.ParaVirtualSCSIController $new.Device.Key = - 100 $new.Device.ControllerKey = $oldCtrl.ControllerKey $new.Device.UnitNumber = $oldCtrl.UnitNumber $new.operation = "add" $spec.DeviceChange += $new $vm.ReconfigVM($spec)
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Fyi, the Switching to the Paravirtual SCSI Controller post has been updated.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I will test this in my environment later today. I was hoping you would see and answer my question. Thanks in advance!
Have a look at the latest comments in that post as well.
Some of the limitations seem to be removed with vSphere 4.1 !
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Worked like a charm! Thank you so much!