What would a PowerShell script be to return versions of the .NET Framework on a machine?
My first guess is something involving WMI. Is there something better?
It should be a one-liner to return only the latest version for each installation of .NET [on each line].
I found this through tab completion in powershell for osx:
[System.Runtime.InteropServices.RuntimeInformation]::get_FrameworkDescription() .NET Core 4.6.25009.03
I would try this one in PowerShell: Worked for me!
(Get-ItemProperty "HKLM:Software\Microsoft\NET Framework Setup\NDP\v4\Full").Version
Nice solution
Try using the downloadable DotNetVersionLister module (based on registry infos and some version-to-marketing-version lookup table).
Which would be used like this:
Or like this if you just want to test it for some .NET framework >= 4.*:
But it will not work (install/import) e.g. with PS v2.0 (Win 7, Win Server 2010 standard) due to incompatibility...
Motivation for "legacy" functions below
(You could skip reading this and use code below)
We had to work with PS 2.0 on some machines and could not install/import the above DotNetVersionLister.
On other machines we wanted to update (from PS 2.0) to PS 5.1 (which in turn needs .NET Framework >= 4.5) with the help of two company-custom
Install-DotnetLatestCompany
andInstall-PSLatestCompany
.To guide admins nicely through the install/update process we would have to determine the .NET version in these functions on all machines and PS versions existing.
Thus we used also the below functions to determine them more safely in all environments...
Functions for legacy PS environments (e.g. PS v2.0)
So the following code and below (extracted) usage examples are useful here (based on other answers here):
Example usage:
Added v4.7.2 support to the script:
Refer to the page Script for finding which .NET versions are installed on remote workstations.
The script there might be useful to find the .NET version for multiple machines on a network.
Correct syntax:
The
GetSystemVersion
function returns a string like this:or like this
$PSVersionTable
is a read-only object. The CLRVersion property is a structured version number like this: