Skip to content

Export Windows OS build numbers

We want to get a list of all the AD computers build numbers. That’s because we like to know if all computers are up to date. An excellent way to get this report is with PowerShell. In this article, you will learn how to export Windows OS build numbers to CSV file.

Check Windows build number

You can get the version and OS build number from the About Windows screen (winver).

This is on Windows Server 2019.

Windows Server OS build number

This is on Windows 10.

Windows 10 OS Build number

But do you want to do this per system? No, you don’t. So PowerShell is the answer.

Export Windows OS build numbers PowerShell script

The Get-WindowsOSBuilds.ps1 PowerShell script loops through each computer, tests if it is online, and if so, checks if WinRM is enabled. If WinRM is enabled, the script retrieves the edition, version, and OS build.

The script gathers the following information for each AD computer:

  1. ComputerName
  2. Status
  3. WinRM
  4. Edition
  5. Version
  6. OSBuild

Important: The Windows Remote Management service needs to be running on every computer to retrieve the information. This can be done by deploying a GPO or other alternatives.

You can identify the WinRM service by the following names:

  • Service name: WinRM
  • Display name: Windows Remote Management (WS-Management)
WinRM service running

Prepare Get-WindowsOSBuilds PowerShell script

Create two folders on the Domain Controller (C:) drive:

  • Temp
  • Scripts

Download the Get-WindowsOSBuilds.ps1 PowerShell script and place it in C:\scripts folder. The script will export the CSV file to the C:\temp folder.

Another option is to copy and paste the below code into Notepad. Give it the name Get-WindowsOSBuilds.ps1 and place it in the C:\scripts folder.

<#
    .SYNOPSIS
    Get-WindowsOSBuilds.ps1

    .DESCRIPTION
    Export Windows OS versions and build numbers to CSV file.

    .LINK
    www.alitajran.com/export-windows-os-build-numbers

    .NOTES
    Written by: ALI TAJRAN
    Website:    www.alitajran.com
    LinkedIn:   linkedin.com/in/alitajran

    .CHANGELOG
    V1.00, 04/16/2023 - Initial version
#>

# Retrieve a list of all computers in the domain
$computers = Get-ADComputer -Filter { OperatingSystem -Like "Windows*" }

# Set the registry path that will be used to retrieve the Windows build numbers
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"

# Initialize progress bar
$total = $computers.Count
$completed = 0
$progress = 0
Write-Progress -Activity "Retrieving Windows build numbers" -Status "Starting..." -PercentComplete $progress

# Loop through each computer and retrieve the Windows versions and build numbers (if the computer is online)
$results = foreach ($computer in $computers) {
    $computerName = $computer.Name
    $online = Test-Connection -ComputerName $computerName -Count 1 -Quiet
    if ($online) {
        $winRMEnabled = (Test-WSMan -ComputerName $computerName -ErrorAction SilentlyContinue) -ne $null
        if ($winRMEnabled) {
            $buildNumber = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "CurrentBuild").CurrentBuild })
            $revisionNumber = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "UBR").UBR })
            $windowsBuildNumber = "$buildNumber.$revisionNumber"
            $edition = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "ProductName").ProductName })
            $version = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "ReleaseID" -ErrorAction Stop).ReleaseID })
        }
        else {
            $windowsBuildNumber = "N/A"
            $edition = "N/A"
            $version = "N/A"
        }
        [PSCustomObject] @{
            "ComputerName" = $computerName
            "Status"       = "Online"
            "WinRM"        = if ($winRMEnabled) { "Enabled" } else { "Disabled" }
            "Edition"      = $edition
            "Version"      = $version
            "OSBuild"      = $windowsBuildNumber
        }
    }
    else {
        [PSCustomObject] @{
            "ComputerName" = $computerName
            "Status"       = "Offline"
            "WinRM"        = "N/A"
            "Edition"      = "N/A"
            "Version"      = "N/A"
            "OSBuild"      = "N/A"
        }
    }
    $completed++
    $progress = [Math]::Round($completed / $total * 100)
    Write-Progress -Activity "Retrieving Windows build numbers" -Status "Completed $completed of $total" -PercentComplete $progress
}

# Sort the results by ComputerName in ascending order and select only the desired columns
$results | Sort-Object ComputerName | Select-Object ComputerName, Status, WinRM, Edition, Version, OSBuild | Export-Csv -Path "C:\Temp\WindowsOSBuilds.csv" -NoTypeInformation

This is how it looks.

Export Windows OS build numbers scripts folder

Run Get-WindowsOSBuilds PowerShell script

Get Windows OS Builds for all AD computers with PowerShell. Change the path to the scripts folder. After that, run the script Get-WindowsOSBuilds.ps1.

PS C:\> cd c:\scripts\
PS C:\scripts> .\Get-WindowsOSBuilds.ps1

Open Windows OS Builds report CSV file

The Get-WindowsOSBuilds.ps1 PowerShell script will export Active Directory Computers build numbers to CSV file. Find the file WindowsOSBuilds.csv in the path C:\temp.

Open the CSV file with your favorite application. In our example, it’s Microsoft Excel.

Export Windows OS build numbers CSV file

The Windows OS Builds report looks excellent.

Important: Don’t forget to disable Windows Remote Management (WinRM) if that’s the policy in the organization.

Did this help you to export Windows OS build numbers to CSV file?

Read more: Uninstall and disable SMBv1 in Windows »

Conclusion

You learned how to export Windows OS build numbers with PowerShell. Get the Windows OS build report with Get-WindowsOSBuilds PowerShell script and review it. Ensure that all the Windows AD computers are up to date for security purposes.

Did you enjoy this article? You may also like Check free disk space on Windows with PowerShell script. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *