VMware Cloud Community
rumyyy
Contributor
Contributor
Jump to solution

Get list of available USB devices connected to ESXi host in PowerCLI.

Hi guys,

I want to get a list of the available USB devices from vSphere PowerCLI. The devices are connected to my ESXi 6.0 server.

I am able to get the list of devices with 'lsusb' from ESXi  Shell.

Also, can I use VendorId or ProductId to connect the USB device to a VM again form PowerCLI.

1 Solution

Accepted Solutions
pwilk
Hot Shot
Hot Shot
Jump to solution

And what if you run ESXi shell commands through SSH connection from Jenkins? This way you could bypass PowerCLI and still run these tests.

Cheers, Paul Wilk

View solution in original post

Reply
0 Kudos
13 Replies
pwilk
Hot Shot
Hot Shot
Jump to solution

Have you seen this doc? Get-UsbDevice

Cheers, Paul Wilk
Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

Yes, that gives you the devices that have been connected to a specific virtual machine. What I need is the list of devices that are available to connect to.

Reply
0 Kudos
pwilk
Hot Shot
Hot Shot
Jump to solution

I don't think what you're trying to accomplish is possible from vSphere level. Have you tried running

tail -f /var/log/vmkernel.log | grep -i USB

from ESXi shell?

If you can get a list of devices using lsusb, why would you insist on using PowerCLI?

Cheers, Paul Wilk
Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

I would like to Revert/Start/Stop/Delete VM as well as connect USB devices to them using the PowerCLI, so that I can run these commands from Jenkins. The purpose of all of this is to to run automated tests on these VMs.

Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

Ideally, I want the connection to the USB devices to be foolproof in order to avoid any failure.

Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

I'm considering to make an usb.autoConnect.device in .vmx file of the VM, but I'm afraid this would give errors if another machine is trying to use the same device. The best way is to get the list of available devices in order to know what is available for use.

Reply
0 Kudos
pwilk
Hot Shot
Hot Shot
Jump to solution

And what if you run ESXi shell commands through SSH connection from Jenkins? This way you could bypass PowerCLI and still run these tests.

Cheers, Paul Wilk
Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

That's an option I considered, but will I be able to start/stop/revert/delete VM from the ESXi Shell?

Reply
0 Kudos
pwilk
Hot Shot
Hot Shot
Jump to solution

ESXi shell:

power on: vim-cmd vmsvc/power.on <vmid>

power off: vim-cmd vmsvc/power.off <vmid>

delete: vim-cmd vmsvc/destroy <vmid>

Here is a list of most common VM-oriented commands in PowerCLI/vMA/ESXi cli VMware Knowledge Base

Cheers, Paul Wilk
Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

Thank you very much!

Reply
0 Kudos
pwilk
Hot Shot
Hot Shot
Jump to solution

You are very welcome my Linux friend Smiley Wink

Please let me know if you'd any further assistance

Cheers, Paul Wilk
Reply
0 Kudos
rumyyy
Contributor
Contributor
Jump to solution

And do you know where I can find the commands for connecting disconnecting a USB device using ESXi shell

Reply
0 Kudos
pwilk
Hot Shot
Hot Shot
Jump to solution

I suggest reading through this doc to better understand vim-cmd commands. Most operations can be "figured out" after reading this https://communities.vmware.com/servlet/JiveServlet/downloadBody/31025-102-1-44609/Quick%20Tutorial%2...

Cheers, Paul Wilk