Background
Sometimes, it's crucial to know the underlying operating system running your Azure App Service. This can help you address compatibility issues during development before deploying to Azure. Unfortunately, Microsoft's documentation does not specify the exact operating system name and version of the Web Worker that runs your application. So, it's up to us to determine this information.
It's important to note that there is no guarantee that all Azure App Service Web Workers are running the same operating system. For instance, during the migration from Windows Server 2016 to 2022, which spanned nearly a year, App Service scale units were upgraded gradually. This means that some servers received the new operating system sooner than others. Which means, the information provided in this blog post might not reflect the system you are using. Always verify the details for your specific environment.
Solution
Just the version number
The typical way for getting Windows OS version is to run the ver
command, which also works in the App Service console.
In case you don't know, the console is located in the side menu of your App Service instance.
Most of the time, this would be enough to determine what's the Windows Version, according to this table:
Version Number | Name |
---|---|
10.0.10240 | Windows 10 Version 1507 |
10.0.10586 | Windows 10 Version 1511 (November Update) |
10.0.14393 | Windows 10 Version 1607 (Anniversary Update) or Windows Server 2016 |
10.0.15063 | Windows 10 Version 1703 (Creators Update) |
10.0.16299 | Windows 10 Version 1709 (Fall Creators Update) |
10.0.17134 | Windows 10 Version 1803 (April 2018 Update) |
10.0.17763 | Windows 10 Version 1809 (October 2018 Update) or Windows Server 2019 |
10.0.18362 | Windows 10 Version 1903 (May 2019 Update) |
10.0.18363 | Windows 10 Version 1909 (November 2019 Update) |
10.0.19041 | Windows 10 Version 2004 (May 2020 Update) |
10.0.19042 | Windows 10 Version 20H2 (October 2020 Update) |
10.0.19043 | Windows 10 Version 21H1 (May 2021 Update) |
10.0.19044 | Windows 10 Version 21H2 (November 2021 Update) |
10.0.19045 | Windows 10 Version 22H2 (2022 Update) |
10.0.20348 | Windows Server 2022 Version 21H2 |
10.0.22000 | Windows 11 Version 21H2 (original release) |
10.0.22621 | Windows 11 Version 22H2 (2022 Update) |
10.0.22631 | Windows 11 Version 23H2 (2023 Update) |
10.0.26100 | Windows 11 Version 24H2 (2024 Update) |
Get the OS full name
If you want to get the friendly name, like "Windows Server 2022", all your favorite commands will blow up:
Even in PowerShell:
In case you don't know, you can get the PowerShell console from the "Advanced Tools" menu in your App Service instance.
Get-ComputerInfo | Select-Object CsName, OsName, WindowsVersion, WindowsBuildLabEx
(Get-WmiObject -Class Win32_OperatingSystem).Caption
The workaround is to read Windows registry. Registry path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
holds the information of the OS full name.
To read a registry value using PowerShell, you can use the Get-ItemProperty
cmdlet.
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$productName = Get-ItemProperty -Path $regPath -Name "ProductName"
$productName.ProductName
Using the same trick, we will also be able to get the server system version from the code of the App that we deploy to Azure App Service, like my ASP.NET Core blog system:
public static string TryGetFullOSVersion()
{
var osVer = Environment.OSVersion;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return osVer.VersionString;
try
{
var currentVersion = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
if (currentVersion != null)
{
var name = currentVersion.GetValue("ProductName", "Microsoft Windows NT");
var ubr = currentVersion.GetValue("UBR", string.Empty).ToString();
if (!string.IsNullOrWhiteSpace(ubr))
{
return $"{name} {osVer.Version.Major}.{osVer.Version.Minor}.{osVer.Version.Build}.{ubr}";
}
}
}
catch
{
return osVer.VersionString;
}
return osVer.VersionString;
}
<td class="text-muted">@Helper.TryGetFullOSVersion() @(Environment.Is64BitOperatingSystem ? "(64-bit)" : "(32-bit)")</td>
Comments