如何在单个输出中使用 get-wmiobject 获取 Antecedent 和从属设备的 PnpDeviceId?

How can I get PnpDeviceId of Antecedent and Dependent device using get-wmiobject in single output?

我想在单个输出中使用 get-wmiobject -class Win32_SCSIControllerDevice(例如在 table 中)获取先行和从属设备的 PnpDeviceId。 我发现我可以做到:

 Get-WmiObject -class Win32_SCSIControllerDevice | ForEach-Object { [WMI]$_.Antecedent}  | Format-Table PnpDeviceId

Get-WmiObject -class Win32_SCSIControllerDevice | ForEach-Object { [WMI]$_.Dependent}  | Format-Table PnpDeviceId

如何嵌套这两个命令以获得如下示例所示的结果?

PnpDeviceId                 PnpDeviceId
-----------                 -----------
PnpDeviceIdAntecedentDevice PnpDeviceIdDependentDevice
PnpDeviceIdAntecedentDevice PnpDeviceIdDependentDevice
PnpDeviceIdAntecedentDevice PnpDeviceIdDependentDevice

编辑:

使用

Get-WmiObject -class Win32_SCSIControllerDevice | ForEach-Object { [WMI]$_.Antecedent, [WMI]$_.Dependent } | Format-Table PnpDeviceId

我得到了:

PnpDeviceId               
-----------                 
PnpDeviceIdAntecedentDevice
PnpDeviceIdDependentDevice
PnpDeviceIdAntecedentDevice 
PnpDeviceIdDependentDevice
PnpDeviceIdAntecedentDevice 
PnpDeviceIdDependentDevice

我尝试了不同的格式,但没有单行格式。

只需 select 使用 Select-Object(别名 select)cmdlet 的属性:

Get-WmiObject -class Win32_SCSIControllerDevice | select Antecedent, Dependent

编辑:

如果您想 select 嵌套 属性,您可以使用自定义 select 语句:

Get-WmiObject -class Win32_SCSIControllerDevice | Select @{e={([WMI]$_.Antecedent).PNPDeviceID}; l='Antecedent PNPDeviceID'}, @{e={([WMI]$_.Dependent).PNPDeviceID}; l='Dependent PNPDeviceID'}

输出:

Antecedent PNPDeviceID                                       Dependent PNPDeviceID                                           
----------------------                                       ---------------------                                           
PCI\VEN_8086&DEV_282A&SUBSYS_05351028&REV_04&11583659&0&FA SCSI\DISK&VEN_LITEONIT&PROD_LCT-256M3S&62C5D10&0&000000       
PCI\VEN_8086&DEV_282A&SUBSYS_05351028&REV_04&11583659&0&FA SCSI\CDROM&VEN_TSSTCORP&PROD_DVD-ROM_TS-U333B&62C5D10&0&010000