powershell 检测DotNet Framework版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 检测DotNet Framework版本相关的知识,希望对你有一定的参考价值。

# 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
        }
    }
"@

以上是关于powershell 检测DotNet Framework版本的主要内容,如果未能解决你的问题,请参考以下文章

通过dotnet cli中的自定义模板创建类时如何检测命名空间

执行 powershell 语句后检测错误

powershell 检测.NET版本

powershell 测试群集检测

powershell 检测并报告循环嵌套的AD组

Powershell 检测设备管理器