Skip to content

Instantly share code, notes, and snippets.

@PanosGreg
Last active April 15, 2024 10:18
Show Gist options
  • Save PanosGreg/bdca14d3a8af09dfbc4555ccfe3e0185 to your computer and use it in GitHub Desktop.
Save PanosGreg/bdca14d3a8af09dfbc4555ccfe3e0185 to your computer and use it in GitHub Desktop.
It provides the equivalent information to winver.exe
function Get-WindowsVersion {
<#
.SYNOPSIS
It provides the equivalent information to winver.exe
.EXAMPLE
Get-WindowsVersion
#>
[cmdletbinding()]
param ()
$Registry = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
if ($Registry.DisplayVersion) {
$Version = '{0} ({1})' -f $Registry.DisplayVersion,$Registry.ReleaseID
$DisplayVer = $Registry.DisplayVersion
}
else {
$Version = $Registry.ReleaseID
$DisplayVer = [string]::Empty
}
switch ($Registry.InstallationType) {
'Client' {$Product = $Registry.ProductName}
'Server' {$Product = '{0} ({1})' -f $Registry.ProductName,'Desktop Experience'}
'Server Core' {$Product = '{0} ({1})' -f $Registry.ProductName,'Server Core'}
default {$Product = $Registry.ProductName}
}
$obj = [pscustomobject] @{
PSTypeName = 'Windows.Version'
Product = $Product
Version = $Version
Build = '{0}.{1}' -f $Registry.CurrentBuild,$Registry.UBR
ProductName = $Registry.ProductName
OSType = $Registry.InstallationType
DisplayVersion = $DisplayVer # <-- ex. 21H1, 22H2, etc...
ReleaseVersion = $Registry.ReleaseID
BuildVersion = $Registry.CurrentBuild
Revision = $Registry.UBR
}
$prop = 'Product','Version','Build'
$pset = [Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',[string[]]$prop)
$Memb = [System.Management.Automation.PSMemberInfo[]]@($pset)
$obj | Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $Memb -PassThru
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment