VMware Cloud Community
wadams
Contributor
Contributor

Disconnecting and re-connecting USB device to VM via command line?

I'm using the free version of vSphere 6.0 (no vCenter, just vSphere Client) at home and am having some problems with usb device that is attached to the server and passed into a VM.  In the VM, the usb device periodically stops working and I have to disconnect and re-connect the device using vSphere Client.  I can do this without shutting down the VM, which is nice, but it is still somewhat of a pain through the gui interface.  Is there a way to do this via the command line rather than using the vSphere Client "Edit Settings" interface?  I installed the vSphere CLI on a windows server, but I only see references in the docs to changing the network interfaces/cdroms/floppy drives.  Not other kinds of devices.

When I look at the .vmx file, the change it appears to be making when I disconnect/reconnect is:

connected:

usb_xhci.autoConnect.device1 = "path:2/0/3 autoclean:1"

disconnected:

usb_xhci.autoConnect.device1 = ""

Any thoughts?

thanks

Wayne

Reply
0 Kudos
3 Replies
virtualg_uk
Leadership
Leadership

This may help, I used it myself a while back:

vSphere USB Passthru and Autoconnect Devices and PowerCLI | mwpreston.net


Graham | User Moderator | https://virtualg.uk
Reply
0 Kudos
wadams
Contributor
Contributor

Seems interesting, but it appears to rely on having vCenter (don't think you can use PowerCLI without it), which I don't have.

Reply
0 Kudos
virtualg_uk
Leadership
Leadership

That's correct.

You might be able to use something like vmware-cmd via SSH / API

vmware-cmd - perform virtual machine operations

vSphere Documentation Center

For example:

vmware-cmd /vmfs/volumes/Storage2/testvm/testvm.vmx connectdevice "USB DRIVE NAME"


Graham | User Moderator | https://virtualg.uk
Reply
0 Kudos