【问题标题】:Filtering Get-WmiObject Class Property Output to include only value过滤 Get-WmiObject 类属性输出以仅包含值
【发布时间】:2019-06-16 16:18:15
【问题描述】:

我一直在使用 Powershell 使用“Get-WmiObject”cmdlet 和关联的类作为脚本的一部分从主机查询项目。 为了找到计算机制造商,我使用以下 Get-WMIObject 命令将返回的属性输出到变量:

PS C:\temp\PS> $VmPhys = Get-WmiObject -Class Win32_ComputerSystem |Select-Object -Property Manufacturer
PS C:\temp\PS> write-host = $VmPhys
= @{Manufacturer=Dell Inc.}

我遇到的问题是,当我将属性值发送到变量时,它还包括属性名称,而不仅仅是上面的值。

PS C:\temp\PS> Get-WmiObject -Class Win32_ComputerSystem |Select-Object -Property Manufacturer

Manufacturer
------------
Dell Inc.

有没有办法排除属性名称而只导出值,例如“Dell Inc.”变量?

【问题讨论】:

    标签: powershell get-wmiobject


    【解决方案1】:

    使用-Expandproperty 而不是property

    Get-WmiObject -Class Win32_ComputerSystem |Select-Object -ExpandProperty Manufacturer
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2018-07-04
      相关资源
      最近更新 更多