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

时间:2016-05-13 14:51:42

标签: powershell get-wmiobject

我希望在单个输出中使用get-wmiobject -class Win32_SCSIControllerDevice(例如在表中)获取前导和从属设备的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

我尝试了不同的格式,但没有符号线。

1 个答案:

答案 0 :(得分:0)

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

Get-WmiObject -class Win32_SCSIControllerDevice | select Antecedent, Dependent

修改

如果要选择嵌套属性,可以使用自定义选择语句:

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\3&11583659&0&FA SCSI\DISK&VEN_LITEONIT&PROD_LCT-256M3S\4&62C5D10&0&000000       
PCI\VEN_8086&DEV_282A&SUBSYS_05351028&REV_04\3&11583659&0&FA SCSI\CDROM&VEN_TSSTCORP&PROD_DVD-ROM_TS-U333B\4&62C5D10&0&010000