VMware Cloud Community
edinburgh1874
Enthusiast
Enthusiast
Jump to solution

Remove all "HD Audio" devices after P2V?

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

9 Replies
LucD
Leadership
Leadership
Jump to solution

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

edinburgh1874
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
edinburgh1874
Enthusiast
Enthusiast
Jump to solution

Sure, it came back with "VirtualHdAudioCard"

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

edinburgh1874
Enthusiast
Enthusiast
Jump to solution

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!

Reply
0 Kudos
ITSavant
Contributor
Contributor
Jump to solution

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 ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ITSavant
Contributor
Contributor
Jump to solution

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)."

Reply
0 Kudos