0

I am running windows PRO

when I run the following command :

(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName

using a regular user in PowerShell the result is Windows 10 PRO though I am running Windows 11

when I run the same command using Admin mode I get :

Windows 10 Enterprise

Which is pretty amazing given the fact that it comes from the same registry key.

I was wondering if it is a bug and if someone have a better way getting the product name (like pro enterprise etc.)

running the same command in powershell (not through a .ps1 file) gives the same results.

  • 1
    Give `Get-CimInstance Win32_OperatingSystem|% Caption` a go – Mathias R. Jessen Nov 24 '22 at 11:30
  • You can also decide what windows version is _actually_ installed by looking at `HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion` item `CurrentBuildNumber`. Windows 10 have numbers there starting at `10000`; Windows 11 starts with `20000` – Theo Nov 24 '22 at 12:47
  • `((Get-CimInstance Win32_OperatingSystem | select name).name).split('|')[0]` - The name property would tell you the actual. Please run it and check. – Ranadip Dutta Nov 24 '22 at 21:22
  • thx Mathias that seems to be working great though I am still not sure why getting it from the registry in 2 different user modes ends with different result... – Avner Hilu Nov 26 '22 at 09:59
  • Does this answer your question? [How to find the Windows version from the PowerShell command line](https://stackoverflow.com/questions/7330187/how-to-find-the-windows-version-from-the-powershell-command-line) – Dennis Nov 29 '22 at 19:13

1 Answers1

0

I have this bit of code. Releaseid seems deprecated. Ubr changes with each monthly update.

# patchcheck.ps1

$reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$releaseid = $reg.releaseid
$ubr = $reg.ubr
$displayversion = $reg.displayversion

[pscustomobject]@{result = 
  switch ($releaseid) {
    '1607' { $ubr -ge '4651' } # kb5005573
    '1709' { $false } 
    '1809' { $false }
    '1903' { $false } 
    '1909' { $ubr -ge '1801' } # KB5005566
    '2004' { $ubr -ge '1288' } # kb5006670
    '2009' { $ubr -ge '1288' } # kb5006670
    default { $false }
  }
  releaseid = $releaseid
  displayversion = $displayversion
  ubr = $ubr
}
icm comp001 patchcheck.ps1 | ft

result releaseid displayversion  ubr PSComputerName RunspaceId
------ --------- --------------  --- -------------- ----------
  True 2009      21H2           2251 comp001        214ba11a-7f1b-453a-a52c-6ea59928780e
js2010
  • 23,033
  • 6
  • 64
  • 66