VMware Cloud Community
chi2109
Contributor
Contributor

How to programmatically add a USB Passthrough device to a guest VM?

Hi,

I've got a ESXi 6.0 host server with a couple of in-house USB devices connected that are configured for USB Passthrough mode. I would like to programmatically (or via command line) add a particular USB device to a guest VM before starting that VM to launch some automated tests. I can do it manually via the vSphere Client GUI but I can't find anything online that would allow me to do it programmatically or via command line. Is there a way?

Thanks in advance.

Chi

0 Kudos
6 Replies
LucD
Leadership
Leadership

Does this script work for you ?

See vSphere USB Passthru and Autoconnect Devices and PowerCLI


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

0 Kudos
chi2109
Contributor
Contributor

Thanks for the reply LucD!

It's not exactly what I'm looking for but I think it's a start. For my situation, I would like to route a particular USB port to a particular VM, irrespective of the PID/VID. So I'm thinking in the deviceName, all I need to assign is the path and hostId, is that correct?

And how do I find the USB Connection Path on the Host?

0 Kudos
LucD
Leadership
Leadership

According to the API Reference, path and hostid should work.

See VirtualUSBUSBBackingInfo.

Not sure how you do the path in the GUI, is that copntroller only and no device ?.

Would you mind sharing a screenshot ?


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

0 Kudos
chi2109
Contributor
Contributor

I don't know how to get the path either. In the API Reference the example given is "path:1/3/0". What do those numbers mean?

0 Kudos
chi2109
Contributor
Contributor

I installed vCenter and using the vCenter Web Client, I added a USB device to a VM. Then I was able to find the "path" in the VM Hardware Settings page (in Edit mode). It appears this information is not in the lightweight vSphere Client but is in the fully featured vCenter Web Client.

I'll now modify mwpreston‌'s script to assign a particular USB device (based on path) to a VM. Will post script here once it's tested.

0 Kudos
sumann7
Contributor
Contributor

@chi2109 Did you managed the script ?

Asking because I have similar requirement but does not look like this can be done.

0 Kudos