Let’s look at several ways to inventory versions and builds of Windows OSs in an Active Directory domain (it is especially relevant for Windows 10). If you haven’t any tools to automatically get computer configurations, such as SCCM, GLPI with FusionInventory, or at least the Windows Server Update (WSUS) host (it also lets you get the Windows version on discovered computers), you can use a PowerShell script to find Windows versions/builds on domain computers.
On a standalone computer, you can get a Windows version and build number from the registry or with SystemInfo:
Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
To get a list of active computers in an Active Directory domain and Windows versions (builds) on them, you can use the Get-ADComputers cmdlet.
Make sure that the Active Directory Module for PowerShell is installed on your computer and run the command below:
Get-ADComputer -Filter {(Enabled -eq $True)} -Property * | Select-Object Name,OperatingSystem,OperatingSystemVersion
To convert the build number of Windows 10 and 11 to a more convenient format (21H1, 21H2, etc.), you need to use an additional function.
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'
}
}
Then, to get a list of Windows versions with hostnames, build numbers, IP addresses, and the computer’s last domain logon, run the following PowerShell script:
$Comps= Get-ADComputer -Filter {(Enabled -eq $True)} -properties *
$CompList = foreach ($Comp in $Comps) {
[PSCustomObject] @{
Name = $Comp.Name
IPv4Address = $Comp.IPv4Address
OperatingSystem = $Comp.OperatingSystem
Build = ConvertWindowsBuild -OperatingSystem $Comp.OperatingSystem -OperatingSystemVersion $Comp.OperatingSystemVersion
LastLogonDate = $Comp.LastLogonDate
}
}
$CompList | Out-GridView
You can display the output as an Out-GridView table or export the list of computers to a CSV file (Export-Csv -Path .\windows_version_report.csv -NoTypeInformation
).
To display a summary statistics on a number of computers with different Windows versions and builds in your domain:
$CompList | Group-Object -Property Build | Format-Table -Property Name, Count
You can also query your computers remotely and get Windows versions on them using PowerShell Remoting. This method is slower, but it allows you to get Windows versions on computers in a workgroup environment (PSRemoting in a Workgroup). To get information from remote computers, you may use the Invoke-Command cmdlet:
Invoke-Command -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild} -ComputerName wsk-w12b21| Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuild
You can get Windows versions on multiple computers according to the list in a TXT file:
Invoke-Command –ComputerName (Get-Content c:\ps\PC_list.txt) -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild}|Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuild
You can use these Powershell scripts to get Windows versions and builds on domain computers, find computers with old (unsupported) Windows 10 builds, and update them (How to Update Windows 10 Build with Command-Line?)