locked
PowerShell equivalent of device manager RRS feed

  • Question

  • I searched this and the Scripting Guys forum, and Related topics, but don't see anything applicable. I would like to be able to inspect all devices that are exposed in Device Manager. I want to get detailed info on driver file versions. I usually display with View -> By Type, Properties on a device, and look at the driver date, I also need the file version from Driver Details -> select a file. Related responses suggest using DevCon, but I don't have this installed, and would rather stay in PS if I can. I would also rather not have to install any other 3rd party software. I've seen some PS and VB scripts that pick out specific device types (something like get-wmiobject with Win32_NetworkAdapter), but I'm looking for some in-house proprietary devices, so I'm not even sure what "type" they would look like. I thought I would be able to get an object/collection/tree of devices, navigate through them, and pick out appropriate ones by matching the inf/sys file names. Some forum responses make it sound difficult, but is there any way to script my way through the devices? Any other ideas (in PowerShell)? Thanks.
    Wednesday, January 4, 2012 2:46 PM

Answers

  • gwmi Win32_SystemDriver | select name,@{n="version";e={(gi $_.pathname).VersionInfo.FileVersion}}
    



    or

    gwmi Win32_PnPSignedDriver | select devicename,driverversion

    • Edited by Kazun Wednesday, January 4, 2012 3:03 PM
    • Proposed as answer by Bigteddy Wednesday, January 4, 2012 3:28 PM
    • Marked as answer by gkd720 Wednesday, January 4, 2012 5:36 PM
    Wednesday, January 4, 2012 3:01 PM
  • couple of things come to mind...
     
    1) WMI - this would be a bit of a pain because I don’t know of a central
    Device list, you'd have to hit up each core class (as you mentioned
    win32_networkadapter) which I suspect would be a long list
     
    2) MSInfo32 - use this utility to spit out a report and then regex the data
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by gkd720 Wednesday, January 4, 2012 5:36 PM
    Wednesday, January 4, 2012 2:54 PM

All replies

  • couple of things come to mind...
     
    1) WMI - this would be a bit of a pain because I don’t know of a central
    Device list, you'd have to hit up each core class (as you mentioned
    win32_networkadapter) which I suspect would be a long list
     
    2) MSInfo32 - use this utility to spit out a report and then regex the data
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by gkd720 Wednesday, January 4, 2012 5:36 PM
    Wednesday, January 4, 2012 2:54 PM
  • gwmi Win32_SystemDriver | select name,@{n="version";e={(gi $_.pathname).VersionInfo.FileVersion}}
    



    or

    gwmi Win32_PnPSignedDriver | select devicename,driverversion

    • Edited by Kazun Wednesday, January 4, 2012 3:03 PM
    • Proposed as answer by Bigteddy Wednesday, January 4, 2012 3:28 PM
    • Marked as answer by gkd720 Wednesday, January 4, 2012 5:36 PM
    Wednesday, January 4, 2012 3:01 PM
  • Hey, thanks to both for the answers. JRich's MSInfo, and both of Kazun's gwmi approaches provide a plethora of information on a test machine. I'll have to run them on the real machine to see if they provide all the pieces I was looking for.

    But I'm still not real clear on a couple of items. Admittedly not a PS expert, I'm going through a couple of books, but I don't completely understand the "gwmi Win32_SystemDriver ... select" syntax. I see the @ generating an anonymous hash, but I never saw it as a select item.

    And in general, how do I find out what properties, or tree of properties, an object has? I experimented with the provided line to better understand how I was getting properties of properties, and get some of the structure from (with the 'where' used to stick with a single driver):

    PS C:\temp> (gi (gwmi Win32_SystemDriver | where {$_ -match "wudfrd"}).pathname).versioninfo.fileversion
    6.0.5716.32 (winmain(wmbla).060928-1756)

    So it seems the driver pathname returns a list of properties, one of which is versioninfo, which is a list of properties, of which I'm picking fileversion? I was a little surprised getting no output from most of these other attempts:

    PS C:\temp> (get-wmiobject win32_systemdriver|where {$_ -match "wudfrd"}).pathname.versioninfo
    PS C:\temp> (get-wmiobject win32_systemdriver|where {$_ -match "wudfrd"}).pathname.version
    PS C:\temp> (get-wmiobject win32_systemdriver|where {$_ -match "wudfrd"}).version
    PS C:\temp> (get-wmiobject win32_systemdriver|where {$_ -match "wudfrd"}).pathname
    C:\WINDOWS\system32\DRIVERS\wudfrd.sys

    Or should I just get-member my way down through each property level?

    Thanks for any insight.

     

    Wednesday, January 4, 2012 5:56 PM
  • ahh calculated properties, they are wonderful things.... basically only good
    with a Select statement... it says @{L="label";e={expression code}}
     
    like if you wanted to change the format of something, or show a property on
    the fly...
     
    in this case Kazun is using it to dig in to a property to bubble it up...
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, January 4, 2012 6:14 PM