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

问题描述:

我想在单个输出(例如表格)中使用get-wmiobject -class Win32_SCSIControllerDevice获取先行和从属设备的PnpDeviceId。 我看着办吧,我可以做:如何在单一输出中使用get-wmiobject获取先行和从属设备的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 

我尝试不同的格式,但有没有劲儿线。

Get-WmiObject -class Win32_SCSIControllerDevice | select Antecedent, Dependent 

编辑:

如果你想选择一个嵌套的属性,你可以使用自定义的select语句:

使用Select-Object(化名select)cmdlet的只是选择属性

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 
+0

这选择整个路径,我只需要什么是在DeviceId之后。我知道我可以解析它,但我正在寻找方式,我有很好,干净的输出 – kendzi

+0

好吧,我添加了一个自定义的选择示例。 –

+0

感谢您的帮助,这对我很好。 – kendzi