calixo
calixo

Reputation: 25

In powershell, adding another set of values from a get-adcomputer result

I've got a working script that gets the result from Get-AdComputer module:

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

Now I am trying to add another column that converts the value from operatingSystemVersion to another.

sample result

Upvotes: 1

Views: 99

Answers (2)

Gabriel Luci
Gabriel Luci

Reputation: 40878

First create a hashtable with your mapping:

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

Then you can use a calculated property that looks up the operatingSystemVersion in the hashtable:

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

Upvotes: 4

Avshalom
Avshalom

Reputation: 8889

Use Calculated Properties

See an Example for the "NewColumn" Change the expression to what you need:

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

Upvotes: 0

Related Questions