Scroll Top
Evotec Services sp. z o.o., ul. Drozdów 6, Mikołów, 43-190, Poland

Getting Windows 10 build version from Active Directory

img_5d03b4c46f7e1

Today I saw an article on how to get Windows Version Report from Active Directory and thought that this is a cool idea. Something handy for migration scenarios or information on how up to date is your infrastructure. Since there are many ways to do the same thing I decided to tackle this myself and further include it into PSWinDocumentation.AD project. By default Active Directory stores Operating System and Operating System Version but it doesn't really show versions one may expect.

Sure it gives us information what system it is but version number is far from being anything Microsoft marketing department uses. So how one can do it? Well, as I've learned recently – there's only one way to do it – via hashtables! It has to be fast and furious. While doing foreach, lots of if/else options we will get the same results for bigger domains it will take time.

Getting Windows 10 Build Version from Active Directory

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.

Posty powiązane