【问题标题】:How can I get PnpDeviceId of Antecedent and Dependent device using get-wmiobject in single output?如何在单个输出中使用 get-wmiobject 获取先行和从属设备的 PnpDeviceId?
【发布时间】:2016-05-13 14:51:42
【问题描述】:

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

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

【问题讨论】:

    标签: powershell get-wmiobject


    【解决方案1】:

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

    Get-WmiObject -class Win32_SCSIControllerDevice | select Antecedent, Dependent
    

    编辑:

    如果要选择嵌套属性,可以使用自定义的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\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
    

    【讨论】:

    • 这会选择整个路径,我只需要 DeviceId 之后的内容。我知道我可以稍后解析它,但我正在寻找我有漂亮和干净的输出的方法
    • 好的,我添加了一个自定义选择示例。
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多