Find Windows OS Versions and Build Numbers

Powershell Script to get windows os versions and build numbers

Jan 2, 2023 - 12:10
Feb 20, 2023 - 13:48
Find Windows OS Versions and Build Numbers

If they are already up and running, it is easy to get the OS Versions and build numbers via SCCM or WSUS. And of course there are some automated tools to get the OS versions and build numbers but there is also another way to get the list from all domain. A quick powershell script can bring the results in a very short time.

**** Run powershell with privileged account

  • Query the local system like this:

Get-WindowsVersion

  • Query for remote computers

Get-WindowsVersion -ComputerName PC001

Get-WindowsVersion -ComputerName @("PC001","PC002","SRV001","SRV002")

Quick Access to Script:

powershell/get_osversions.ps1 at main · kbsuperuser/powershell (github.com)

  • Script 1:

-------*******-------

<#
.SYNOPSIS
    Get OS Versions
.DESCRIPTION
    This PowerShell script scans the domain and lists "ComputerName, OSName, Version and BuildNumber". Scripts export the results to CSV file. Update the target path before running. The execution time of the scripts depends on range of network and speed. Priviligied account is needed to use the script.
.EXAMPLE
    PS> ./get_osversions

.LINK
    https://github.com/kbsuperuser/powershell
.NOTES
    Author: kbsuperuser.com | License: CC0
#>

$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
$output = @()
foreach ($computer in $computers) {
    try {
        $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
        $osInfo = [PSCustomObject]@{
            ComputerName = $computer
            OSName = $os.Name
            Version = $os.Version
            BuildNumber = $os.BuildNumber
        }
        $output += $osInfo
    } catch {
        Write-Error "Unable to retrieve OS information from $computer"
    }
}

$output | Export-Csv -Path "C:\path\to\osversions.csv" -NoTypeInformation

-------*******-------

  • Script 2:

-------*******-------

function ConvertWindowsBuild{
[CmdletBinding()]
param(
[string] $OperatingSystem,
[string] $OperatingSystemVersion
)
if (($OperatingSystem -like '*Windows 10*') –or ($OperatingSystem -like 'Windows 11*')) {
$WinBuilds= @{
'10.0 (22621)' = "Windows 11 22H2"
'10.0 (19045)' = "Windows 10 22H2"
'10.0 (22000)' = "Windows 11 21H2"
'10.0 (19044)' = "Windows 10 21H2"
'10.0 (19043)' = "Windows 10 21H1"
'10.0 (19042)' = "Windows 10 20H2"
'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'
}
$WinBuild= $WinBuilds[$OperatingSystemVersion]
}
else {$WinBuild = $OperatingSystem}
if ($WinBuild) {
$WinBuild
} else {
'Unknown'
}
}

$Comps= Get-ADComputer -Filter {(Enabled -eq $True)} -properties *
$CompList = foreach ($Comp in $Comps) {
[PSCustomObject] @{
Name = $Comp.Name
Description = $Comp.Description
IPv4Address = $Comp.IPv4Address
OperatingSystem = $Comp.OperatingSystem
Build = ConvertWindowsBuild -OperatingSystem $Comp.OperatingSystem -OperatingSystemVersion $Comp.OperatingSystemVersion
BuildVersion = $Comp.OperatingSystemVersion
LastLogonDate = $Comp.LastLogonDate
}
}
$CompList | Out-GridView
$CompList | Group-Object -Property Build | Format-Table -Property Name, Count

-------*******-------

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow