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.
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.
What would be the SELECT
statement to use?
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