01 September, 2018

Powershell: Show Windows version build info, with UBR

I wanted to pull in all of the Windows version info into a variable...
Release Number, Build Number, and UBR / 'Update Build Revision'

These standard commands were lacking -
  • Get-WindowsEdition -Online 
  • [environment]::OSVersion
  • [environment]::OSVersion.Version
  • (Get-CimInstance Win32_OperatingSystem)version

The 'Release Number' and UBR don't show up.

The UBR is not super useful, except for adding completeness...
But the 'Release Number' is what most Windows version conversations rely on.

Sure, one can type 'winver', and see it in a pop-up window...
But I wanted something more tangible, and portable... As a $variable

Mostly - I wanted figure out how to get to this info from the command-line...

Anyway - It's in the Registry...
This does not require elevation. And it can be pulled in with one line (well two, but really one):
Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' `
select ReleaseID,CurrentBuildNumber,UBR


Or it can be prettied up with three lines:
$Reg_NT_CurVer = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' `
select ReleaseID,CurrentBuildNumber,UBR
$BuildNo = ($Reg_NT_CurVer.CurrentBuildNumber)+"."+($Reg_NT_CurVer.UBR)
Write-Host " Version" $Reg_NT_CurVer.ReleaseID "(OS Bulld" $BuildNo") " -BackgroundColor Black
# On lines '1' and '2' above, that select is not really needed - I just put it there for clarity

Some additional notes:
# ReleaseID / Release is coded 'YYMM' - So, for example: '1803', was released 2018 March
# CurrentBuildNumber / CBN
# UBR is 'Update Build Revision'

# Below is just another way of putting the same info on screen.
# I re-labled the headers. The 'Out-String trim', just removes extra lines'

Write-Host "~~~~~~~~~~~~~~" -ForegroundColor Yellow
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' `
FL @{L='Release';E={$_.ReleaseID}},@{L='CBN';E={$_.CurrentBuildNumber}},@{L='UBR';E={$_.UBR}} `
| Out-String).Trim()     # (FL = format-list)

Write-Host "~~~~~~~~~~~~~~" -ForegroundColor Yellow
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' `
FT @{L='Release';E={$_.ReleaseID}},@{L='CBN';E={$_.CurrentBuildNumber}},@{L='UBR';E={$_.UBR}} `

| Out-String).Trim()     # (FT = format-table)