如何找到相关的 Win32_PnpSignedDriver 实例?

如何找到相关的 Win32_PnpSignedDriver 实例?

要获取当前设备及其驱动程序的列表,我可以使用 Windows 上的 Powershell 执行以下操作:

> $drvdev = gwmi Win32_SystemDriverPnpEntity

然后检查返回的Win32_SystemDriverWin32_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...

但除了上面返回的信息之外Win32_SystemDriver,该类中还有更多关于该驱动程序的信息Win32_PnpSignedDriver

> $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
...

Win32_PnpSignedDriver当我从对开始时,找到任何对应实例的正确方法是什么Win32_SystemDriver/PnpEntity

答案1

坚持你的方法,对于非经常性使用(一次命中):

$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('\','\\'))'"

但是,你可以应用ASSOCIATORS OF陈述WMI 查询语言 (WQL),例如如下:

$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

示例输出,排序并截断(使用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...

相关内容