Hi All,
Is anyone aware of a way in PowerCLI to mass remove all "HD Audio" devices from VMs in a cluster?
I can't find a commandlet for this particular device (e.g get-floppydrive)
I've recently built a development cluster, however I've found that my colleagues have imported 300 VMs from VMWare Workstation...having the HD Audio device breaks DRS and vMotion!
Cheers
Try like this
$vmName = "MyVM"
$vm = Get-VM -Name $vmName
$audio = $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualHdAudioCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $audio
$dev.Operation = "remove"
$spec.deviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just to clarify, are these audio devices you see in the VM settings, or inside the guest OS in the device manager ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thanks for your reply - just the devices in "VM Settings".
Having this attached to the VM breaks vMotion, but removing it allows migration.
Cheers
Can you run the following ?
It should list all the connected devices
$vmName = "MyVM"
$vm = Get-VM -Name $vmName
$vm.ExtensionData.Config.Hardware.Device | %{
$_.GetType().Name
}
To avoid we are removing the incorrect device
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sure, it came back with "VirtualHdAudioCard"
Thanks
Try like this
$vmName = "MyVM"
$vm = Get-VM -Name $vmName
$audio = $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualHdAudioCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $audio
$dev.Operation = "remove"
$spec.deviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect...works great!
I guess I just need to find some way of putting this into a loop, to remove all HD Audio devices from all registered VMs.
Thanks!
It should be noted that the VMs I tested required being powered OFF to remove the VirtualHdAudioCard.
I tested powered ON and Suspended, and both failed.
Microsoft Windows 7 Professional SP1
VMware PowerShell Version: 5.0.10586.117
MS .Net Version: 4.5.51209
VMware PowerCLI Version: 6.3
vCenter 5.5
ESXi 5.5 U3
VM vHW version vmx-10
VM OS: W2K3 <=== Maybe works with a newer OS ?
Did you also try after adding devices.hotplug = "true" in the VMX file?
But ultimately it's the guest OS that has to cope with the hot removal of HW
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I combined your statements into the following:
$vmName = "MyVM"
$vm = Get-VM -Name $vmName
$vmview = $vm | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="devices.hotplug"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vmview.ReconfigVM($vmConfigSpec)
$audio = $vm.ExtensionData.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualHdAudioCard"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Device = $audio
$dev.Operation = "remove"
$spec.deviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
And still found the same result:
Exception calling "ReconfigVM" with "1" argument(s): "The attempted operation cannot be performed in the current state (Powered on)."