VMware Cloud Community
ajdovahkiin
Contributor
Contributor
Jump to solution

is there a way to pass a USB device to the VM from the guest machine using PowerCLI?

Hi Guys,

I have installed the vSphere PowerCLI on my machine. Is it possible to map a USB device connected to my machine to a vSphere VM through command line? I am able to do this currently using the vSphere client UI.

When i went though the PowerCLI documentation I could find only "Get-UsbDevice" and "Remove-UsbDevice". I need something to Add-Usbdevice and list USB devices. Please let me know if there is any way to achieve it from command line. Greatly appreciate you help in this matter.

Thanks,

-Ajith

1 Solution

Accepted Solutions
ajdovahkiin
Contributor
Contributor
Jump to solution

Finally figured out a way to do that. It is possible using VMRC SDK. I am able to connect devices from my web page. Feel free to mail me if anyone needs any help in achieving this.

View solution in original post

14 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik, connecting a VM to local USB devices, which can be done through the GUI, is done through private API.

So Im afraid there are no command line alternatives.

Btw the 2 USB related cmdlets you mention are for USB devices that are connected to the host, not the client.

There was a recent thread on this. See Discover USB Devices available for passthru


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

ajdovahkiin
Contributor
Contributor
Jump to solution

Thanks LucD for the quick response. Is there any way to automatically connect USB devices to the VM from the client machine?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not that I know of.


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

0 Kudos
ajdovahkiin
Contributor
Contributor
Jump to solution

I came across the vSphere web client SDK today. I am wondering if its possible to build a plugin using the SDK to connect client USB devices?

If the answer is "yes" then i will go ahead and try to implement it.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

With the ReconfigVM_Task method you can do some actions of host (ESXi) connected USB devices.

But local USB devices use private API afaik.

So no, there will not be a method in the SDK I'm afraid


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

0 Kudos
ajdovahkiin
Contributor
Contributor
Jump to solution

that's bad news for me Smiley Sad. I was building an app that needed to automatically map some phones to specific VM's. Looks like the user has to do it manually now. Thanks for saving my time LucD, otherwise i would have spent hours trying to figure it. Please let me know if VMware opens up the API in future or if you have any other idea's on how to solve this problem.

0 Kudos
thejuskrishna
Contributor
Contributor
Jump to solution

Can we have an API in CLI for connecting through the command line interface? At least is that there in any paid version?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm not sure what you mean with "paid" version in this context.

Afaik, the feature to attach local USB devices is only there in the vSphere client.

And that is based on a private API, similar to for example attaching a local ISO file.


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

0 Kudos
ajdovahkiin
Contributor
Contributor
Jump to solution

Finally figured out a way to do that. It is possible using VMRC SDK. I am able to connect devices from my web page. Feel free to mail me if anyone needs any help in achieving this.

LucD
Leadership
Leadership
Jump to solution

Great, would be nice if you could share the method you used.

If you use the VMRC SDK, isn't the solution limited to web applications only ?


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

0 Kudos
ajdovahkiin
Contributor
Contributor
Jump to solution

Yes this solution is limited to web applications because it connects to the browser client via java-script.

The SDK has a very nice example html page (vmrc-embed-example.html). The steps involved are

1) Create the browser plugin object

2) Start the plugin with an appropriate mode using vmrc.startup()

3) vmrc.getPhysicalClientDevices() will return an array of devices

4) vmrc.getPhysicalClientDeviceDetails() will return individual device details

5) vmrc.connect() will connect to a VM

6) vmrc.connectDevice() will connect it to the VM

thejuskrishna
Contributor
Contributor
Jump to solution

Thanks ajdovahkin!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks for sharing that


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

0 Kudos
ghalan_Matthieu
Contributor
Contributor
Jump to solution

I'm interrested in this solution. Could you give us a sample ?

0 Kudos