Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 226373

Re: Discover USB Devices available for passthru

$
0
0

Well I'm looking forward to it...

 

If it helps - this is the complete script I ended up using ...

 

Add-PSSnapin VMware.VIMAutomation.Core

 
$vcserver = "vcenterserver"

$vcusername = "username"

$vcpassword = "password"

 

$myhost = "Host that USB is attached to"

$myvm = "VM which to pass USB through to"

 

$pid = "PID of USB Device"

$vid = "VID of USB Device"

 

Connect-VIserver $vcserver -user $vcusername -pass $vcpassword

 

 

#get id of VM

$vm = get-vm $myvm

$vmid = $vm.ID

 

#get host uuid from BIOS

$vmhost = get-vmhost $myhost

$vmhostId =  $vmhost.ExtensionData.Hardware.SystemInfo.Uuid

 

#reformat vmhostID to the proper format for autoconnect string

$vmhostd = $vmhostid.Replace("-","")

$section1 = $vmhostid.substring(0,16)

$section2 = $vmhostid.substring(16)

$newsec1 = (&{for ($i = 0;$i -lt $section1.length;$i += 2)   {     $section1.substring($i,2)   }}) -join '\ '

$newsec2 = (&{for ($i = 0;$i -lt $section2.length;$i += 2)   {     $section2.substring($i,2)   }}) -join '\ '

$hostId = "$newsec1-$newsec2"

 

 

#create usb device and add it to the VM.

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "add"

$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualUSB

$spec.deviceChange[0].device.key = -100

$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualUSBUSBBackingInfo

$spec.deviceChange[0].device.backing.deviceName = "pid:$pid vid:$vid hostId:$hostId"

$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$spec.deviceChange[0].device.connectable.startConnected = $true

$spec.deviceChange[0].device.connectable.allowGuestControl = $false

$spec.deviceChange[0].device.connectable.connected = $true

$spec.deviceChange[0].device.connected = $false

 

$_this = Get-View -Id "$vmid"

$_this.ReconfigVM_Task($spec)

 

Viewing all articles
Browse latest Browse all 226373

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>