For the purpose of easy asking for Windows 10 version, I've created a simple function, that I will reuse doing foreach scenario.
function ConvertTo-OperatingSystem {
[CmdletBinding()]
param(
[string] $OperatingSystem,
[string] $OperatingSystemVersion
)
if ($OperatingSystem -like 'Windows 10*') {
$Systems = @{
'10.0 (18362)' = "Windows 10 1903"
'10.0 (17763)' = "Windows 10 1809"
'10.0 (17134)' = "Windows 10 1803"
'10.0 (16299)' = "Windows 10 1709"
'10.0 (15063)' = "Windows 10 1703"
'10.0 (14393)' = "Windows 10 1607"
'10.0 (10586)' = "Windows 10 1511"
'10.0 (10240)' = "Windows 10 1507"
'10.0 (18898)' = 'Windows 10 Insider Preview'
}
$System = $Systems[$OperatingSystemVersion]
} elseif ($OperatingSystem -notlike 'Windows 10*') {
$System = $OperatingSystem
}
if ($System) {
$System
} else {
'Unknown'
}
}
I've filled in some versions to use in my example, but surely it needs some updating to cover a whole range of systems you may have in your own Active Directory.
$Computers = Get-ADComputer -Filter * -properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate, whenCreated
$ComputerList = foreach ($_ in $Computers) {
[PSCustomObject] @{
Name = $_.Name
OperatingSystem = $_.OperatingSystem
OperatingSystemVersion = $_.OperatingSystemVersion
System = ConvertTo-OperatingSystem -OperatingSystem $_.OperatingSystem -OperatingSystemVersion $_.OperatingSystemVersion
LastLogonDate = $_.LastLogonDate
WhenCreated = $_.WhenCreated
}
}
$ComputerList | Group-Object -Property System | Format-Table -Property Name, Count
$ComputerList | Format-Table -AutoSize
And voila! We have two ways to display our systems. First, we used Group-Object to provide a count of systems, other one gave us a full list with an additional column called System that has data you need. Now I need to make sure it's integrated into PSWinDocumentation.AD so that next time I need it, it's there, waiting for me.