[Environment]::Version reports the CLR (the runtime) version, which is not the same as the .NET Framework version, which is the independently versioned class library[1] that builds on a given CLR version.
To get the framework version, use the following, which returns a string such as
.NET Framework 4.8.4341.0:
[System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
Note:
This property is available in .NET Framework 4.7.1 and above, and Windows PowerShell in recent Windows versions is built on v4.8.
- Caveat: As Bacon Bits reports, version
2.0 of the PSReadLineModule module can shadow the property due to inexplicably being bundled with an older version of the [System.Runtime.InteropServices.RuntimeInformation] class. Windows PowerShell versions up to at least Windows 11 22H2 ship with 2.0, so you must manually upgrade the PSReadLine module to version 2.1 or higher (2.2.6 is current as of this writing), e.g. with
Install-Module -Force PSReadLine -Scope CurrentUser; see the comments for details.
If it isn't available, you can try the following, which yields a string such as "4.8.04084":[2]
Get-ItemPropertyValue 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' Version
If that doesn't work either, the implication is that your .NET Framework version is lower than 4.5
[1] In the cross-platform .NET Core / .NET 5+ edition, there is only a unified runtime that also includes the class library, which [Environment]::Version correctly reflects in .NET Core 3.0 and later.
[2] Curiously, this version differs in the revision number from the one reported by [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription (if available). There's yet another variant with a differing revision, as part of the InstallPath value from the same registry key; e.g. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\