【问题标题】:In powershell, adding another set of values from a get-adcomputer result在 powershell 中,从 get-adcomputer 结果中添加另一组值
【发布时间】:2022-01-22 09:44:18
【问题描述】:

我有一个从Get-AdComputer 模块获取结果的工作脚本:

Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties *  | 
  Select -Property operatingSystem,operatingSystemVersion

现在我正在尝试添加另一列,将值从 operatingSystemVersion 转换为另一列。

【问题讨论】:

    标签: powershell active-directory


    【解决方案1】:

    首先使用您的映射创建一个hashtable

    $os = @{
      "10.0 (19042)" = "20H2"
      "10.0 (19043)" = "21H1"
    }
    

    然后您可以使用calculated property 在哈希表中查找operatingSystemVersion

    Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties *  | 
       Select -Property operatingSystem,operatingSystemVersion,
       @{N="Codename";E={$os[$_.operatingSystemVersion]}}
    

    【讨论】:

    • 太棒了!感谢您的帮助。
    【解决方案2】:

    使用Calculated Properties

    查看“NewColumn”的示例将表达式更改为您需要的内容:

    Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties *  | 
    Select -Property operatingSystem,operatingSystemVersion,
    @{N="NewColumn";E={$_.operatingSystem.ToUpper()}}
    

    【讨论】:

    • 感谢您的回复。现在我正在尝试使用 operatingSystemVersion 中的值将其转换为另一个值(1903、1909、20H2 或 21H1)。
    猜你喜欢
    • 2019-01-06
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 2018-11-12
    • 2012-07-16
    相关资源
    最近更新 更多