Skip to content

Instantly share code, notes, and snippets.

@bryder
Created June 4, 2016 21:23
Show Gist options
  • Save bryder/f79b3c059fa571841e20f6d42d22289d to your computer and use it in GitHub Desktop.
Save bryder/f79b3c059fa571841e20f6d42d22289d to your computer and use it in GitHub Desktop.
get vid and pids from windows usb list in poweshell
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where {( $_.Description -match "storage" -or $_.Description -match "usb") -and $_.Description -notmatch "hub"}
$regex = '.*VID_(?<vid>[0-9A-F]{4})&PID_(?<pid>[0-9A-F]{4}).*'
$usb_devices | foreach { if ($_.deviceid -match $regex) { add-member -inputobject $_ @{VID=$matches['vid']; PID=$matches['pid']} -passthru } else { $_ }} | sort pnpclass,name | ft Name, manufacturer, pnpclass, deviceid, vid, pid
# some variatinos on select the devices
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where {( $_.Description -match "storage" -or $_.Description -match "usb") -and $_.Description -notmatch "hub"}
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where { $_.Description -notmatch "hub"}
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment