Saturday, September 1, 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'
https://2.bp.blogspot.com/-K8ywTdl-FOM/W4vxEU5ycRI/AAAAAAABxLg/IFSG-lio-y0jHHETkQhXXP-CyZEfaUyXwCLcBGAs/s400/OSv04.jpg








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
https://2.bp.blogspot.com/-jaQmfLwCBPc/W4tck4BhYGI/AAAAAAABxK8/8V-NzOGx_Ucz12foZfsMsXdORSQJnkfxQCEwYBhgL/s1600/OSv02.jpg

 


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
https://4.bp.blogspot.com/-nSh8vHsEjSI/W4tcwYdU3sI/AAAAAAABxLA/hPyeRt9CRXoGsPgzJb7J2myaVtIlzsfKwCEwYBhgL/s1600/OSv01.jpg



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)
https://4.bp.blogspot.com/-B4w7ImrZXWc/W4tdeQe6pNI/AAAAAAABxLI/J2hUr5Y1RhEQ4Hp-ritC1Lp8VMjghnUjQCLcBGAs/s1600/OSv03.jpg