1

我想在单个输出(例如在表中)使用 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

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

4

1 回答 1

0

只需使用Select-Object (alias 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
于 2016-05-13T15:23:13.820 回答