Advertisement
guyrleech

Parse pnputil.exe output to PowerShell objects

Mar 19th, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Convert output of pnputil.exe to objects.
  2. ## Should work with any output where items are delimited by a blank line and the property name and value are delimited by a :
  3. <#
  4. Instance ID:                PCI\VEN_17CB&DEV_010E&SUBSYS_00000000&REV_00\3&36cb97a3&2&00
  5. Device Description:         PCI Express Root Port
  6. Class Name:                 System
  7. Class GUID:                 {4d36e97d-e325-11ce-bfc1-08002be10318}
  8. Manufacturer Name:          (Standard system devices)
  9. Status:                     Started
  10. Driver Name:                pci.inf
  11.  
  12. Instance ID:                HID\VID_046D&PID_C52B&MI_00\a&3081608f&0&0000
  13. Device Description:         HID Keyboard Device
  14. Class Name:                 Keyboard
  15. Class GUID:                 {4d36e96b-e325-11ce-bfc1-08002be10318}
  16. Manufacturer Name:          (Standard keyboards)
  17. Status:                     Started
  18. Driver Name:                keyboard.inf
  19. #>
  20.  
  21. $o = $null ; pnputil.exe /enum-devices /connected | Select -skip 2 | % { $f = $_.Trim() ; if( $f -match '^\s*$' ) { if( $o ) { $o ; $o = $null } } else { if( -Not $o ) { $o = New-Object pscustomobject }; if( $f.IndexOf( ':' ) -gt 0 ) { $s = ($f -split ':' , 2).Trim() ; Add-Member -InputObject $o -MemberType NoteProperty -Name $s[0] -Value $s[-1] } } }|ogv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement