How do I find which Windows version I\'m using?
I\'m using PowerShell 2.0 and tried:
PS C:\\> ver
The term \'ver\' is not recognized as the name o
If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200) use
(Get-CimInstance Win32_OperatingSystem).Version
to get the proper version. [Environment]::OSVersion
doesn't work properly in Windows 8.1 (it returns a Windows 8 version).
I searched a lot to find out the exact version, because WSUS server shows the wrong version. The best is to get revision from UBR registry KEY.
$WinVer = New-Object –TypeName PSObject
$WinVer | Add-Member –MemberType NoteProperty –Name Major –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMajorVersionNumber).CurrentMajorVersionNumber
$WinVer | Add-Member –MemberType NoteProperty –Name Minor –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentMinorVersionNumber).CurrentMinorVersionNumber
$WinVer | Add-Member –MemberType NoteProperty –Name Build –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' CurrentBuild).CurrentBuild
$WinVer | Add-Member –MemberType NoteProperty –Name Revision –Value $(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' UBR).UBR
$WinVer
[solved]
#copy all the code below:
#save file as .ps1 run and see the magic
Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption
(Get-CimInstance Win32_OperatingSystem).version
#-------------comment-------------#
#-----finding windows version-----#
$version= (Get-CimInstance Win32_OperatingSystem).version
$length= $version.Length
$index= $version.IndexOf(".")
[int]$windows= $version.Remove($index,$length-2)
$windows
#-----------end------------------#
#-----------comment-----------------#
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
returns
WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Enterprise 1709 10.0.16299.371
Windows PowerShell 2.0:
$windows = New-Object -Type PSObject |
Add-Member -MemberType NoteProperty -Name Caption -Value (Get-WmiObject -Class Win32_OperatingSystem).Caption -PassThru |
Add-Member -MemberType NoteProperty -Name Version -Value [Environment]::OSVersion.Version -PassThru
Windows PowerShell 3.0:
$windows = [PSCustomObject]@{
Caption = (Get-WmiObject -Class Win32_OperatingSystem).Caption
Version = [Environment]::OSVersion.Version
}
For display (both versions):
"{0} ({1})" -f $windows.Caption, $windows.Version
This will give you the full version of Windows (including Revision/Build number) unlike all the solutions above:
(Get-ItemProperty -Path c:\windows\system32\hal.dll).VersionInfo.FileVersion
Result:
10.0.10240.16392 (th1_st1.150716-1608)