在 powershell 中,从 get-adcomputer 结果中添加另一组值
In powershell, adding another set of values from a get-adcomputer result
我有一个工作脚本可以从 Get-AdComputer
模块获得结果:
Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties * |
Select -Property operatingSystem,operatingSystemVersion
现在我正在尝试添加另一列,将值从 operatingSystemVersion
转换为另一个。
查看“NewColumn”示例 将表达式更改为您需要的内容:
Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties * |
Select -Property operatingSystem,operatingSystemVersion,
@{N="NewColumn";E={$_.operatingSystem.ToUpper()}}
首先使用您的映射创建 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]}}
我有一个工作脚本可以从 Get-AdComputer
模块获得结果:
Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties * |
Select -Property operatingSystem,operatingSystemVersion
现在我正在尝试添加另一列,将值从 operatingSystemVersion
转换为另一个。
查看“NewColumn”示例 将表达式更改为您需要的内容:
Get-ADComputer -Filter 'operatingSystem -like "*Windows 10*"' -Properties * |
Select -Property operatingSystem,operatingSystemVersion,
@{N="NewColumn";E={$_.operatingSystem.ToUpper()}}
首先使用您的映射创建 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]}}