WQL Query to get all devices connected to a specific hub

0

What is the WMI / WQL Query syntax to get all devices connected to a specific USB Hub?

I can open up a PS terminal and enumerate all USB Hub Devices, as such:

 gwmi Win32_UsbHub | fl *

The output will return a list of all USB Hub device on the system. Here is a sampling of one such device.

Device ID: USB\VID_0451&PID_DD01\6&16FAF918&1&2, PNP Device ID: USB\VID_0451&PID_DD01\6&16FAF918&1&2, Description: Generic SuperSpeed USB Hub
    Availability
    Caption=Generic SuperSpeed USB Hub
    ClassCode
    ConfigManagerErrorCode=0
    ConfigManagerUserConfig=False
    CreationClassName=Win32_USBHub
    CurrentAlternateSettings
    CurrentConfigValue
    Description=Generic SuperSpeed USB Hub
    DeviceID=USB\VID_0451&PID_DD01\6&16FAF918&1&2
    ErrorCleared
    ErrorDescription
    GangSwitched
    InstallDate
    LastErrorCode
    Name=Generic SuperSpeed USB Hub
    NumberOfConfigs
    NumberOfPorts
    PNPDeviceID=USB\VID_0451&PID_DD01\6&16FAF918&1&2
    PowerManagementCapabilities
    PowerManagementSupported
    ProtocolCode
    Status=OK
    StatusInfo
    SubclassCode
    SystemCreationClassName=Win32_ComputerSystem
    SystemName=JMR-ENG-SARAH
    USBVersion

Using say the PNPDeviceID for this hub, I would like to get all connected devices, if any to it.

I am totally green with PS and WMI, but I thought of using ASSOCIATES OF as follows:

Get-WmiObject Win32_PnPEntity | select "ASSOCIATORS OF {Win32_UsbHub.DeviceID='USB\VID_0451&PID_DD01\6&16FAF918&1&2'}"

Annoyingly, enumerations do not list parent and children, though Device Manager does list things nicely and has a Parent.

Device Manager view of a <code>Generic USB Hub</code> and <code>Generic SuperSpeed USB Hub</code> Showing Children

Maybe just the way that I phrased things. Many other ways threw an error, so I did research and saw this syntax. I originally thought of using a gwmi command. In any event, I know from Device Manager that there are connected devices, but the above command yielded a blank screen.

WMI Explorer was not much help.

WMI Explorer

What would be the SELECT statement to use?

Sarah Weinberger

Posted 2018-08-17T20:53:27.847

Reputation: 523

Answers

0

Wow!... WMI Explorer, I've not seen that used in years. I still have it though, and others like it. PowerShellScript-o-Matic and the like 8^}

There are better ones instead of WMI Explorer, all written in PS. Check out:

http://blog.ctglobalservices.com/powershell/kaj/coretech-wmi-and-powershell-browser

https://gallery.technet.microsoft.com/PoweShell-ISE-Addon-CIM-5c9af37a

Anyway, as for you query. Not all things are possible with PS alone. There are lots of instances where you have to use real code, meaning, C#/C/C+/C++ to get this sort of stuff.

A lot of what you see in such MMC's of the OS are calls directly to some DLL/OCX file / programming reference, that is not directly exposed for PS to act on directly. This is why Add-Type exists, so, one can add C#/C/C+/C++, other language constructs to get or interop with what is needed.

All that being said... Is this, closer to what you are after?

Get-WmiObject -Class Win32_USBControllerDevice | 
%{[wmi]($_.Dependent)} |
Sort Manufacturer,Description,DeviceID |
Format-Table -AutoSize -GroupBy Manufacturer Description,Service,DeviceID

   Manufacturer: (Generic USB Audio)

Description      Service  DeviceID                                     
-----------      -------  --------                                     
USB Audio Device usbaudio USB\VID_047F&PID_C009&MI_00\8&461FC04&0&0000 
USB Audio Device usbaudio USB\VID_17A0&PID_0305&MI_00\9&109E1BB1&0&0000


   Manufacturer: (Standard keyboards)

Description         Service DeviceID                                     
-----------         ------- --------                                     
HID Keyboard Device kbdhid  HID\VID_045E&PID_00DB&MI_00\A&163A9F80&0&0000


   Manufacturer: (Standard monitor types)

Description         Service DeviceID                          
-----------         ------- --------                          
Generic PnP Monitor monitor DISPLAY\ACI2183\C&8538F4&0&UID256 
Generic PnP Monitor monitor DISPLAY\ACI27F6\8&5458763&0&UID256
Generic PnP Monitor monitor DISPLAY\ACI27F6\8&5458763&0&UID257

Or this...

Get-WmiObject Win32_PNPEntity | 
Select Manufacturer,Description,Name,Service,DeviceID

Or see this...

Device Management PowerShell Cmdlets

This module exposes cmdlets that calls into SetupAPI functions and provides device enumeration and management functions.

https://gallery.technet.microsoft.com/Device-Management-7fad2388

Update per OP comment

As per my comment to you. This should be useful for what you are after. You can read the whole article, it's short, but I've added the salient points here.

UsbTreeView : View Usb devices and hubs they are in in a user friendly form

http://flow-morewithless.blogspot.com/2014/05/usbtreeview-view-usb-devices-and-hubs.html

you cannot get information about the connections because Microsoft wants that information to be hidden Only way to get the child-parent-connection information would be to to go to driver level.

A Visual C project compiled to an EXE.

https://github.com/mkielar/get-parent-device

Create a friendly name list (Powershell hash array) is in file UsbDeviceNames.ps1

$OwnUsbDeviceNames = @{
"USB\VID_04E5&PID_0605\6&13F4C3E&0&6"    = "Hama 4port passive USB hub ( the grey one)";
"USB\VID_1A40&PID_0101\6&DF2EE03&0&5"    = "Deltaco Active Usb 2.0 cable";
"USB\VID_1A40&PID_0101\7&19BC4090&0&1"    = "Delock USB2.0 4port active mini hub (the black round one)";
"USB\VID_0403&PID_6001\FTFSDFHD"        = "FTDI Serial (COM5) to projector";
"USB\VID_0403&PID_6001\FTFXXLHS"        = "FTDI Serial (COM8) to tv";
"Something" = "is nothing"
}

The PS tool

https://github.com/MarkoMarjamaa/UsbTreeView

postanote

Posted 2018-08-17T20:53:27.847

Reputation: 1 783

thank you for taking the time to answer, however no. What I am after is that I specify the device ID of a specific USB hub, such as "Generic SuperSpeed USB Hub USBHUB3 USB\VID_0451&PID_DD01\6&16FAF918&1&2" and get back all the devices plugged into that hub. Yes, I realize that some external USB hubs have a "root" sub hub, which require going one-level deeper to gain access to all the devices plugged into the hub. Device Manager does a nice job, just I need to do the same in code. – Sarah Weinberger – 2018-08-20T15:11:04.633

The other scenario here is that the string you say you want to use are 4 different properties (Name, Caption) and the *ID (Device,PnP) strings contains several chars that are considered reserved / special in PS, thus char termination comes into play. DM does this by design of course, and like many things, MS is known for doing a good deal of stringifying stuff to make it more human readable, though the actual source is not like what is displayed. I done a bit more playing around, and thus far not looking promising. – postanote – 2018-08-21T02:00:09.133

Assuming a C# solution, then how would the solution look? Obviously, the solution is possible, as Device Manager shows the hub and the plugged in devices. – Sarah Weinberger – 2018-08-21T03:55:00.247

I am a true data hog, and when I find stuff interesting, I save it knowing it may come back to help or haunt me sooner or later. See my update for you. You'll note that the solution is two parts. A VC executable and then the PS stuff. It's not my code, just and item I have from circa 2014. – postanote – 2018-08-21T06:51:54.627