To get 21H2 for example on Windows 10, you can do :
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name DisplayVersion).DisplayVersion
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We have the GUI method to get Windows version and "version", ie Windows 8, 10 or 11 and for Windows 10, we have for example "version" 21H2.
So, what is the equivalence in program? Say in PowerShell, what is the command to get the value? I really mean the value, so that my script can run a if-then-else clause to do things differently according to the versions.
Thanks
To get 21H2 for example on Windows 10, you can do :
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name DisplayVersion).DisplayVersion
Just like the add the voices saying 'wtf' (as if it'll make any difference)
@Castorix31 your script worked for me once I got rid of space at the start of line 25 and 14.
However, the results on Win11 are...interesting! Shortname is still windows 10, Longname is Windows 11 (Pro in my case)
I made this PowerShell test script (.ps1), only tested on Windows 10, where I get :
Add-Type -TypeDefinition @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class User32
{
[DllImport("User32.dll", CharSet=CharSet.Unicode)]
public static extern int MessageBox(
IntPtr hWnd,
String lpText,
String lpCaption,
int uType);
}
"@
Add-Type -TypeDefinition @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class WinBrand
{
[DllImport("Winbrand.dll", CharSet = CharSet.Unicode)]
public static extern string BrandingFormatString(string sFormat);
}
"@
$sShortName = [WinBrand]::BrandingFormatString("%WINDOWS_SHORT%");
$sLongName = [WinBrand]::BrandingFormatString("%WINDOWS_LONG%");
$sMessage = "Short name = " + $sShortName + "`n" + "Long name = " + $sLongName
[User32]::MessageBox(0, $sMessage, "Information", 0x00000040) | Out-Null
you can try this;: but I have no Windows 11, so don't know what it returns
Get-WMIObject win32_operatingsystem | select Caption, Version