Get-WmiObject search Win32_OperatingSystem issues

Hello,

learning some basic PowerShell and have some confusion as follows:

Upgrading the local computer system from win10 x86_64 to win11 x86_64.

use some powershell command check there still win 10.

PS C:\Users\auggie> Get-WmiObject -class Win32_OperatingSystem                                                                                                                                                                                       SystemDirectory : C:\WINDOWS\system32
Organization    :
BuildNumber     : 22635
RegisteredUser  : auggie
SerialNumber    : 00330-80130-99582-AA260
Version         : 10.0.22635
PS C:\Users\auggie> (Get-WmiObject Win32_OperatingSystem).Caption -Match "Windows 11"
True
PS C:\Users\auggie>
PS C:\Users\auggie> (Get-WmiObject Win32_OperatingSystem).Caption -Match "Windows 10"
False
PS C:\Users\auggie>
PS C:\Users\auggie> (Get-WmiObject Win32_OperatingSystem).Caption
Microsoft Windows 11 xxx
PS C:\Users\auggie>
PS C:\Users\auggie>
PS C:\Users\auggie>
PS C:\Users\auggie> (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ProductName')
Windows 10 Pro
PS C:\Users\auggie> (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')
2009
PS C:\Users\auggie>
PS C:\Users\auggie> Get-ComputerInfo | Select-Object WindowsVersion

WindowsVersion
--------------
2009

PS C:\Users\auggie> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      22635  0

PS C:\Users\auggie>

What’s the question here?

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.

You’re assuming the version should show 11 under major? Here are the windows 11 build numbers

I’m guessing you have a insider build? Microsoft doesn’t list 10.0.22635.x yet.

2 Likes

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
    }
}

It sounds like there may be some overlap there depending on the version you upgraded from?
https://techcommunity.microsoft.com/t5/windows-management/windows-10-21h2-and-windows-11-21h2-both-show-up-as-quot-2009/m-p/2994441

Yeah but even this is going to report Windows 10 on a windows 11 system. At least it does with me:

I’m running windows 11 Enterprise, but because of how the reg keys are, it thinks I’m running Windows 10.

However,

something like this reports properly:

systeminfo | findstr /B /C:"OS Name" /B /C:"OS Version"

Which Outputs Microsoft Windows 11 Enterprise

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-WmiObject -class Win32_OperatingSystem).Caption
(Get-WmiObject -class Win32_OperatingSystem).Name

Caption probably bit easier to use

3 Likes

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

Since 22H2 is the last version of Windows 10 the ReleaseID 23H2 gives a strong hint that you are in fact running Windows 11. :point_up:t3: :man_shrugging:t3:

1 Like

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.

1 Like

No … Yes. :wink:

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. :smirk:

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. :man_shrugging:t3:

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):

  1. 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.
  2. 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.
  3. OP asked for a command to check ‘current system version’. In this context they are referring to Windows 10 or Windows 11 I believe.
  4. 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!

1 Like

I did not see this line, my apologies.

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.

1 Like

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.

@dotnVo @krzydoug nice.

(Get-WmiObject -class Win32_OperatingSystem).Caption
(Get-WmiObject -class Win32_OperatingSystem).Name

Thanks a lot for everyone’s enthusiastic responses, I truly appreciate it.

1 Like