Introduction
While working on a script I use with Exchange, I noticed that I was unable to detect the version of .NET that was installed as 4.8 on a Windows 2022 server. With a quick search of Microsoft’s .NET documentation, I realized that the version of .NET on Windows Server 2022 had a different release number than on Windows Server 2019. In order to accommodate this variance, I added code to detect the OS version and then use the appropriate Release version to indicate that .NET 4.8 was present.
PowerShell Code
First two lines of code pull the .NET Release value from the registry as well as capturing the OS version of the server:
$NETval = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -Name "Release" $OS = (Get-WmiObject -class Win32_OperatingSystem).Caption
Next the value of .NET Release is compared against known versions (528039 is 4.8 on Server 2019 while 528449 is 4.8 on Server 2022). The first block determines if the version is greater than 4.8:
If ($NETval.Release -gt "528049") { If ($OS -like '*2022*') { If ($NETval.Release -gt "528449") { Write-Host 'Greater than .NET 4.8 is installed.' } } Else { Write-Host 'Greater than .NET 4.8 is installed.' } }
In this section we look for Windows 2022 ($OS like ‘*2022*’) and the Release value is ‘528449’
If (($OS -like '*2022*') -and ($NETval.Release -eq '528449')) { Write-Host '.NET 4.8 is installed.' }
Then we can review the Release value when the OS is Windows 2019
If (($OS -like '*2019*') -and ($NETval.Release -eq '528049')) { Write-Host '.NET 4.8 is installed' }
Comments? Questions?
That’s it for this Quick PowerShell. Feel free to leave your Comments below!