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

Time:12-21

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

CodePudding user response:

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]}}

CodePudding user response:

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()}}
  • Related