関連する Win32_PnpSignedDriver インスタンスを見つけるにはどうすればいいですか?

関連する Win32_PnpSignedDriver インスタンスを見つけるにはどうすればいいですか?

現在のデバイスとそのドライバーのリストを取得するには、Windows 上の Powershell を使用して次の操作を実行します。

> $drvdev = gwmi Win32_SystemDriverPnpEntity

そして返されたWin32_SystemDriverと を調べます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...

ただし、上記で返された情報に加えて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...

関連情報