Get a list of versions and builds of Windows in an Active Directory domain.

In the article, we will consider several ways to inventory the version and builds of Windows (this is especially true for Windows 10) in the Active Directory domain. If you have computer configuration automation tools such as SCCM, GLPI with FusionInventory, or at least the WSUS update server (it also allows you to show the version of Windows on discovered computers), you can use a PowerShell script to get Windows builds on computers.

On a standalone Windows computer, you can get the build number from the registry or from 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 versions (builds) of Windows on them, you can use the Get-ADComputers cmdlet.

Remember to periodically disable and remove inactive computer accounts in the domain.

Make sure you have the Active Directory PowerShell module installed on your computer and run the command:

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 familiar 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 (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'
}
}
Now, to get a list of Windows versions with build names, IP addresses, and the last logon (registration) date of the computer in the domain, 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
The result is provided as an Out-Gridview table or exported to CSV ( Export-Csv -Path .\win_builds_report.csv -NoTypeInformation).

To display summary statistics on the number of computers with different versions of Windows in a domain:

$CompList | Group-Object -Property Build | Format-Table -Property Name, Count


You can also query computers remotely and get the version of Windows on them via PowerShell Remoting. This method is much slower, but allows you to get the version of Windows on computers that are in a workgroup (how to remotely connect to a computer in a workgroup through PSRemoting). To get information from remote computers, you can use the Invoke-Command cmdlet:

Invoke-Command -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild} -ComputerName wsk-w10BO1| Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuild
You can get the version of Windows on several computers according to the list from a txt file:

Invoke-Command –ComputerName (Get-Content c:\ps\comps.txt) -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild}|Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuild

Using the reviewed PowerShell scripts, you can determine the versions and builds of Windows on domain computers, find computers with outdated builds of Windows 10 and update them (an example of updating a Windows 10 build from the command line).

Отправить комментарий

Добавлять новые комментарии запрещено.*

Новые Старые