Search code examples
powershellwmi

Getting a USB Device Instance Path in Powershell


I have a USB device with VID=XXXX and PID=YYYY attached. I'd like to get the end of the Device Instance Path using powershell. For example, if the actual path is USB\VID_XXXX&PID_YYYY\001122334455 then I want 001122334455.

I was trying something like this just to get the device properties, but I'm not getting anywhere:

Get-WmiObject -Class Win32_PnPEntity -Namespace "root\CIMV2" -Filter "PNPDeviceID='USB\\VID_XXXX&PID_YYYY'" |Format-List *

Can anybody suggest the correct way to get the value I'm looking for through Powershell?


Solution

  • Try using LIKE instead of = in your Filter, like so:

    (Get-WmiObject -Class Win32_PnPEntity -Namespace "root\CIMV2" -Filter "PNPDeviceID like 'USB\\VID_XXXX&PID_XXXX%'").PNPDeviceID.Substring(22)