Win10 is upgraded to win11, and some of the registry may not be updated normally.
What kind of command should I use to check the current system version, and use different commands to query and get different results?
Normally, the results should be consistent.
Ok now i’m tracking, and that is interesting. I wrote a function for for a while back to mimic the output of winver but for Powershell. Checking that it looks like I leveraged the registry to get what I wanted:
Function Get-WinVer {
<#
.Synopsis
A Powershell equivalent of the winver.exe command
.Description
Provides Windows version output similar to that of winver.exe but as an object for better use throughout Powershell
.Example
PS> Get-WinVer
ProductName ReleaseID Version
----------- --------- -------
Windows 10 Enterprise 1909 10.0.18363.2158
Output is an object with similar properties to what is returned from winver.exe
.Example
PS> $WinVer = Get-WinVer
PS> $WinVer.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 18363 2158
The Version property returned in the command output is a Version object which is helpful for making comparisons to other versions. Especially if they're cast with the [Version] object.
.NOTES
Version: 1.0
Author: C. Bodett
Creation Date: 03/24/2022
Purpose/Change: Initial function development
#>
$RegKey = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
if ($RegKey.DisplayVersion) {
$ReleaseID = $RegKey.DisplayVersion
} else {
$ReleaseID = $RegKey.ReleaseID
}
$Version = [Version]('{0}.{1}.{2}.{3}' -f $RegKey.CurrentMajorVersionNumber,$RegKey.CurrentMinorVersionNumber,$RegKey.CurrentBuildNumber,$RegKey.UBR)
[PSCustomObject] @{
ProductName = $RegKey.ProductName
ReleaseID = $ReleaseID
Version = $Version
}
}
Even Get-ComputerInformation on my Windows 11 box reports Windows 10. I remember helping someone else out with this a long time ago. I felt like I researched it and the stupid MS answer was ‘for compability reasons’.
Lastly, you may consider using the ‘Caption’ or ‘name’ property on the WMI call
Get-ComputerInformation has a OsName name property that correctly reports windows 11 as well. Though if wanting to run against remote systems you’d probably have to use Invoke-Command
I think that’s besides the point. I am aware that 22H2 is the last version of Windows10, but there’s other concerns there I think using that. Did you have specific concern with what I suggested or just commenting? Definitely open to feedback, as there could totally be better ways I’m not aware of!
OP wasn’t necessarily looking to use that, they are trying to find an easy way to determine if a system is windows 10 or windows 11. I had a reason I didn’t suggest that. ReleaseID does not correlate to a version of Windows in all cases; it’s not always a hint because Windows 11 has 22H2, and 21H2 versions: Windows 11 - release information | Microsoft Learn.
While I agree, it returning 23H2 means Windows 11, returning a different value doesn’t translate necessary, For example, Am I running Win10 or Win11 if I run this script and use ReleaseID and reports back 21H2 or 22H2? You could of course check two things then… or you can do what I suggested and make use of those other properties.
It may be different for others but I work in an environment where we run the latest supported versions of Windows. So I don’t need to consider having Windows 10 and Windows 11 both with a ReleaseID of 21H2 or 22H2.
Apart from that I wouldn’t wonder longer than 2 minutes about the strange versioning of Windows if I see that there is a caption saying Windows 11 I’d be satisfied.
I think we might be on the same page here but sometimes there’s a language barrier. If you’re stating you’d be perfectly ok with trusting a computer is windows 11 based on the caption property, I agree, I would be too, which is why I suggested just using it. The rest of the discussion is probably a bit off track, and while I do have lots of thoughts, here’s not the best place.
In summary (mostly sharing for everyone else as a TLDR):
OP had a concern that some of the ‘registry’ is not updated normally and wanted a command to check version. OP is correct in that registry keys on Windows 11 boxes can report ‘Windows 10’ despite it appearing like they should state Windows 11. (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ProductName') is a good example and it reports back Windows 10 on Windows 11 boxes. When I read about this a while back I feel like the only reason I got was ‘compatibility’. All of my Windows 11 boxes (I have… 5 at this point I think, some build fresh using Windows 11 media, some not), report Windows 10, instead of being Windows 11 with the previous mentioned line of code.
OP shared code that was reporting back OS version, which is also not necessarily relaible on seeing if a box is windows 10 or 11.
OP asked for a command to check ‘current system version’. In this context they are referring to Windows 10 or Windows 11 I believe.
If OP is looking for a reliable method, I think using the caption property is probably ‘good enough’. If they want more details they have those options as well.
If OP is actually looking for something different they can respond back and clarify and we can do our best to guide them!
I was aware of the overlapping 21H2/22H2, but I wasn’t aware of this reporting issue. That’s very unfortunate. I wonder why they have/chose to keep it this way.
I agree and I’m curious if this is exactly what systeminfo or get-computerinfo use.
looking to learn through experimenting with PowerShell to get more familiar with scripting on Windows. I know PowerShell isn’t directly tied to Windows, as the name suggests.
I’ve found errors when querying through registry references, whereas the encapsulated PowerShell commands for querying are correct. Also, I’ve encountered various peculiar permission issues when running PowerShell scripts on Windows, which I’m still learning to navigate.