Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 657 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PowerShell script to return versions of .NET Framework on a machine?

#1
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].
Reply

#2
[environment]::Version

Gives you an instance of [`Version`][1] for the CLR the current copy of PSH is using (as documented [here][2]).


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
Not pretty. *Definitely* not pretty:

ls $Env:windir\Microsoft.NET\Framework | ? { $_.PSIsContainer } | select -exp Name -l 1

This may or may not work. But as far as the latest version is concerned this should be pretty reliable, as there are essentially empty folders for old versions (1.0, 1.1) but not newer ones – those only appear once the appropriate framework is installed.

Still, I suspect there must be a better way.
Reply

#4
I'm not up on my PowerShell syntax, but I think you could just call [System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()][1]. This will return the version as a string (something like `v2.0.50727`, I think).


[1]:

[To see links please register here]

Reply

#5
Correct syntax:

[System.Runtime.InteropServices.RuntimeEnvironment]::GetSystemVersion()
#or
$PSVersionTable.CLRVersion

The [`GetSystemVersion`](

[To see links please register here]

) function returns a string like this:

v2.0.50727 #PowerShell v2.0 in Win 7 SP1

or like this

v4.0.30319 #PowerShell v3.0 (Windows Management Framework 3.0) in Win 7 SP1

[`$PSVersionTable`](

[To see links please register here]

) is a read-only object. The CLRVersion property is a structured version number like this:

Major Minor Build Revision
----- ----- ----- --------
4 0 30319 18444
Reply

#6
Here's the general idea:

Get child items in the .NET Framework directory that are containers whose names match
the pattern *v number dot number*. Sort them by descending name, take the first object,
and return its name property.

Here's the script:

(Get-ChildItem -Path $Env:windir\Microsoft.NET\Framework | Where-Object {$_.PSIsContainer -eq $true } | Where-Object {$_.Name -match 'v\d\.\d'} | Sort-Object -Property Name -Descending | Select-Object -First 1).Name
Reply

#7
gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' |
sort pschildname -des |
select -fi 1 -exp pschildname

This answer doesn't return 4.5 if that is installed. The answer below from @Jaykul and using recurse does.
Reply

#8
There's no reliable way to do this for all platforms and architectures using a simple script. If you want to learn how to do it reliably, start at the blog post *[Updated sample .NET Framework detection code that does more in-depth checking][1]*.

[1]:

[To see links please register here]

Reply

#9
Refer to the page [*Script for finding which .NET versions are installed on remote workstations*][1].

The script there might be useful to find the .NET version for multiple machines on a network.

[1]:

[To see links please register here]

Reply

#10
I found this through tab completion in powershell for osx:


`[System.Runtime.InteropServices.RuntimeInformation]::get_FrameworkDescription()
.NET Core 4.6.25009.03`
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through