PowerShell: Retreive the Update Build Release (UBR)

Created November 22, 2023

In the realm of PowerShell, determining the version of the operating system is a common task for sysadmins. However, when it comes to reporting, extracting additional details, such as the Update Build Release (UBR), becomes crucial. While the Winver tool is a popular choice for obtaining the build, including the UBR, PowerShell provides a more versatile approach.

Unveiling the UBR: Going Beyond the Basics

Registry Magic

One way to retrieve the UBR is through the registry:

PowerShell:
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' –Name UBR).UBR
Output:
3570

This straightforward command quickly fetches the UBR, but what if you need more comprehensive information?

Exploring Get-ComputerInfo

To delve deeper into the operating system details, the Get-ComputerInfo command is a powerful tool. Specifically, the 'OsHardwareAbstractionLayer' property contains the complete string with the UBR:

PowerShell:
(Get-ComputerInfo).OsHardwareAbstractionLayer
Output:
10.0.19041.3570
Harnessing the [System.Version] Class

For a structured representation of the version information, the [System.Version] class proves invaluable. While [System.Environment]::OSVersion.Version provides the basics, including Major, Minor, Build, and Revision, it lacks the UBR. To include the UBR, cast the 'OsHardwareAbstractionLayer' property:

PowerShell:
[Version](Get-ComputerInfo).OsHardwareAbstractionLayer
Output:
Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19041  3570

Now, the output displays the detailed version information, including the UBR.

Scaling Up: Managing Multiple Systems

But what if you're dealing with multiple computers? PowerShell offers a solution. Introducing Microsoft Graph, and if you are leveraging Intune, you can seamlessly fetch information from the cloud:

PowerShell:
import-module microsoft.graph.devicemanagement
[Version](Get-MGDeviceManagementManagedDevice -Filter "deviceName eq 'YouNameIt'").OSVersion
Output:
Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19041  3570

This method enables you to obtain the necessary information from the cloud with a simple Microsoft Graph call, making it especially handy for managing multiple devices efficiently.

Building Your PowerShell Toolbelt

In conclusion, by combining registry queries, Get-ComputerInfo, and the [System.Version] class, you've crafted a robust toolkit for extracting detailed operating system information. Whether you're working on a single machine or managing an entire fleet of devices through the cloud, PowerShell equips you with the flexibility to streamline your patching processes.

If you have any thoughts or feedback on this topic, feel free to share them with me on Twitter at Christian Ritter.

Best regards, Christian