1

To get a list of current devices and their drivers I can do the following with Powershell on Windows:

> $drvdev = gwmi Win32_SystemDriverPnpEntity

and then examine the returned Win32_SystemDriver and Win32_PnpEntity:

> [wmi] $drvdev[49].Antecedent
...
__GENUS                     : 2
__CLASS                     : Win32_PnPEntity
__SUPERCLASS                : CIM_LogicalDevice
...

> [wmi] $drvdev[49].Dependent | fl *
...
Status                  : OK
Name                    : MEIx64
State                   : Running
ExitCode                : 0
Started                 : True
ServiceSpecificExitCode : 0
__GENUS                 : 2
__CLASS                 : Win32_SystemDriver
__SUPERCLASS            : Win32_BaseService
__DYNASTY               : CIM_ManagedSystemElement
__RELPATH               : Win32_SystemDriver.Name="MEIx64"
__PROPERTY_COUNT        : 22
__DERIVATION            : {Win32_BaseService, CIM_Service, CIM_LogicalElement, CIM_ManagedSystemElement}
__NAMESPACE             : root\cimv2
__PATH                  : \\HOMESRV2\root\cimv2:Win32_SystemDriver.Name="MEIx64"
AcceptPause             : False
AcceptStop              : True
Caption                 : Intel(R) Management Engine Interface
CreationClassName       : Win32_SystemDriver
Description             : Intel(R) Management Engine Interface...

But in addition to the info returned in the Win32_SystemDriver above, there is more information about this driver in the Win32_PnpSignedDriver class:

> $pnpdrv = gwmi Win32_PnpSignedDriver
> $pnpdrv[86]
__GENUS                 : 2
__CLASS                 : Win32_PnPSignedDriver
__SUPERCLASS            : CIM_Service
__DYNASTY               : CIM_ManagedSystemElement
__RELPATH               :
__PROPERTY_COUNT        : 28
__DERIVATION            : {CIM_Service, CIM_LogicalElement, CIM_ManagedSystemElement}
__NAMESPACE             : root\cimv2
__PATH                  :
Caption                 :
ClassGuid               : {4d36e97d-e325-11ce-bfc1-08002be10318}
CompatID                : PCI\VEN_8086&DEV_1E3A&REV_04
CreationClassName       :
Description             : Intel(R) Management Engine Interface
DeviceClass             : SYSTEM
DeviceID                : PCI\VEN_8086&DEV_1E3A&SUBSYS_84CA1043&REV_04\3&11583659&0&B0
DeviceName              : Intel(R) Management Engine Interface
...

Which is the correct way to find any corresponding Win32_PnpSignedDriver instance when I start from the Win32_SystemDriver/PnpEntity pair?

2

Insisting upon your approach, feasible for a nonrecurring use (one time hit):

$drvdev = gwmi Win32_SystemDriverPnpEntity

# examine the returned Win32_PnpEntity
[wmi] $drvdev[49].Antecedent

# examine the returned Win32_SystemDriver
[wmi] $drvdev[49].Dependent | Format-List -Property *

# a way to find any corresponding Win32_PnpSignedDriver instance
Get-WmiObject -Class Win32_PnpSignedDriver -Filter `
    "DeviceId = '$(([wmi]$drvdev[49].Antecedent).DeviceId.Replace('\','\\'))'"

However, you could apply the ASSOCIATORS OF Statement of the WMI Query Language (WQL), e.g. as follows:

$devices = Get-WmiObject -Class Win32_PnPEntity | ForEach-Object {
    $Win32_PnPEntity = $_
    $Query = "ASSOCIATORS OF " +
             "{Win32_PnPEntity.DeviceID='$($Win32_PnPEntity.DeviceID)'}" +
             " WHERE AssocClass = Win32_SystemDriverPnpEntity"
    Get-WmiObject -Query $Query -ErrorAction SilentlyContinue | 
        ForEach-Object {
            [PSCustomObject]@{
                Name            = $PSItem.Name;
                SystemDriver    = $PSItem.DisplayName;
                PnPEntity       = $Win32_PnPEntity.DeviceID;
            }
    }
}
### Add properties from the "Win32_PnpSignedDriver" class ###
$PnpSignedDrivers = Get-WmiObject -Class Win32_PnpSignedDriver
foreach ( $device in $devices ) {
   $device |Add-Member -MemberType NoteProperty -Name PnpSignedDriver -Value $(
        $PnpSignedDrivers | 
            Where-Object {$_.DeviceId -eq $device.PnPEntity} |
            ForEach-Object { if ( $_.FriendlyName) 
                { $_.FriendlyName } else { "== $($_. DeviceName)" }

            }     
    )
}
$devices

Sample output, sorted and truncated (using Select-Object -first 5):

PS D:\PShell> $devices = D:\PShell\SU\1439079.ps1
PS D:\PShell> $devices | Sort-Object -Property SystemDriver |
>>         Select-Object -First 5 -Property Name,
>>             SystemDriver, PnpSignedDriver, PnPEntity
Name         SystemDriver                    PnpSignedDriver                         PnPEntity
----         ------------                    ---------------                         ---------
BasicDisplay BasicDisplay                    == Microsoft Basic Display Driver       ROOT\BASICDISPLAY\0000
BasicRender  BasicRender                     == Microsoft Basic Render Driver        ROOT\BASICRENDER\0000
cdrom        CD-ROM Driver                   TSSTcorp CDDVDW SH-224DB                SCSI\CDROM&VEN_TSSTCORP&PROD_CDDVDW_...
CompositeBus Composite Bus Enumerator Driver == Composite Bus Enumerator             ROOT\COMPOSITEBUS\0000
disk         Disk Driver                     KINGSTON SHFS37A120G                    SCSI\DISK&VEN_&PROD_KINGSTON_SHFS37A...
  • It looks like your script finds the PnpEntity/SystemDriver pair, which I already do (in another way) as described in my question. But I want to also find any Win32_PnpSignedDriver instance when/if it is available and I don't see that in your script? – mikewse May 20 '19 at 21:13
  • @mikewse Answer updated. – JosefZ May 21 '19 at 15:33
  • Great thanks - I see now that the DeviceID column is used for mapping in the Win32_PnpSignedDriver instances. Marking as answer! – mikewse May 21 '19 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.