Get connected port number and hub number of the device
powershell, windows
Solution
You need to list the USB device IDs using WMI, then lookup each in the registry to get the location information, if any exists...
$devices = gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)}|select DeviceID
$devices.DeviceID | %{Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\$_"}|
select Mfg,DeviceDesc,HardwareID,LocationInformation,Class
Produces info like this on my machine:
Mfg : @msmouse.inf,%msmfg%;Microsoft
DeviceDesc : @msmouse.inf,%hid.mousedevice%;HID-compliant mouse
HardwareID : {HID\VID_15CA&PID_00C3&REV_0512, HID\VID_15CA&PID_00C3,
HID_DEVICE_SYSTEM_MOUSE, HID_DEVICE_UP:0001_U:0002...}
LocationInformation :
Class : Mouse
Mfg : @usb.inf,%generic.mfg%;(Standard USB Host Controller)
DeviceDesc : @usb.inf,%usb\composite.devicedesc%;USB Composite Device
HardwareID : {USB\VID_0408&PID_2FB1&REV_0901, USB\VID_0408&PID_2FB1}
LocationInformation : Port_#0004.Hub_#0003
Class : USB
Problem
I used to get Device information of the connected USB device using the following command ``` gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Sort Manufacturer,Description,DeviceID | Ft -GroupBy Manufacturer DeviceID ``` How to get connected port number and hub number of the device using Windows Powershell?