Created
March 1, 2018 09:32
-
-
Save nordineb/33e8a1e95e7103e73db4b8f3ae2aa578 to your computer and use it in GitHub Desktop.
Detect DotNet Framework Versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credits to https://stackoverflow.com/questions/3487265/powershell-script-to-return-versions-of-net-framework-on-a-machine | |
# Get the text from github | |
$url = "https://raw.githubusercontent.com/dotnet/docs/master/docs/framework/migration-guide/how-to-determine-which-versions-are-installed.md" | |
$md = Invoke-WebRequest $url -UseBasicParsing | |
# Replace the weird text in the tables, and the padding | |
# Then trim the | off the front and end of lines | |
$map = $md -split "`n" -replace " installed [^|]+" -replace "\s+\|" -replace "\|$" | | |
# Then select all the lines that start with ".NET Framework" | |
# and make sure we don't have duplicates | |
Select-String "^.NET" | Select -Unique | |
# Then remove the .NET Framework | |
$map = $map -replace ".NET Framework " -join "`n" | |
# And just output the script | |
Invoke-Expression @" | |
`$Lookup = ConvertFrom-Csv 'Version|Release | |
$map | |
' -Delimiter "|" | |
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | | |
Get-ItemProperty -name Version,Release -EA 0 | | |
Where { `$_.PSChildName -match '^(?!S)\p{L}'} | | |
Select PSChildName, Version, Release, @{ | |
name="Product" | |
expression={ | |
`$Lookup | ? Release -eq `$_.Release | % Version | |
} | |
} | |
"@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment