【问题标题】:how to amend formatting of output如何修改输出格式
【发布时间】:2012-12-24 20:19:42
【问题描述】:

当我执行以下操作时,我得到的格式为“@{xxx}”...如何只获取计算机描述而没有其他格式?

$CompDes = Get-WmiObject -Class Win32_OperatingSystem |选择 说明

Write-Host "计算机描述 $CompDes"

输出:

Computer Description @{Description=TESING_SERVER}

谢谢,

【问题讨论】:

    标签: powershell


    【解决方案1】:
    $CompDes = Get-WmiObject -Class Win32_OperatingSystem | Select -exp Description
    Write-Host "Computer Description $CompDes"
    

    -exp-ExpandProperty 的缩写。它获取指定属性的值。

    【讨论】:

      【解决方案2】:

      另一种方式:

      $CompDes = Get-WmiObject -Class Win32_OperatingSystem | Foreach-Object {$_.Description}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-07
        • 2022-01-21
        • 1970-01-01
        • 1970-01-01
        • 2019-08-19
        • 2019-01-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多