March 5, 2017

Windows OS version from registry with PowerShell

March 05, 2017 No comments
The program winver.exe (About Windows) displays Windows OS version information by combining registry data values. I wrote a small PowerShell script to show the differences between the new (=> v10.0) and the old (<= v6.3) OS versioning format. Tested on Windows 8.1, Windows 10 and Windows Server 2012 R2.

W10 winver.ps1
W10 winver.ps1
The variable MMBR strings the major, minor, build and revision number together. If the registry has no entry for the major or minor number, the missing value in MMBR is shown as EMPTY. If the major and the minor value are both missing, they get replaced by the old version number.

W12R2 winver.ps1
W12R2 winver.ps1

winver.exe old and new versioning


# Ron Bos,, 2017, v0.2
write-host `
`n"Edition:"(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').ProductName `
`n"Version:"([String]$Version=(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').CurrentVersion)`
`n"Release:"(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').ReleaseID `
`n `
`n"Major:"([String]$Major=(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber) `
`n"Minor:"([String]$Minor=(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').CurrentMinorVersionNumber) `
`n"Build:"([String]$Build=(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').CurrentBuild) `
`n"Revis:"([String]$Revision=(gp 'HKLM:Software\Microsoft\Windows NT\CurrentVersion').UBR)

if (($Major) -and ($Minor)) {
$MMBR=(echo MMBR : $Major"."$Minor"."$Build"."$Revision)
write-host $MMBR -foregroundcolor green
if (($Major) -and !($Minor)) {
$MMBR=(echo MMBR : $Major"."EMPTY"."$Build"."$Revision)
write-host $MMBR -foregroundcolor green
if (!($Major) -and ($Minor)) {
$MMBR=(echo MMBR : EMPTY"."$Minor"."$Build"."$Revision)
write-host $MMBR -foregroundcolor green
if (!($Major) -and !($Minor)) {
$MMBR=(echo MMBR : $Version"."$Build"."$Revision)
write-host $MMBR -ForeGroundColor green