Проверка установленных версий .NET на Windows 10 через PowerShell

Краткий вариант:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version

Развёрнутый вариант:

Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' |
Where-Object { ($_.PSChildName -ne "v4") -and ($_.PSChildName -like 'v*') } |
ForEach-Object {
    $name = $_.Version
    $sp = $_.SP
    $install = $_.Install
    if (-not $install) {
        Write-Host -Object "$($_.PSChildName)  $($name)"
    }
    elseif ($install -eq '1') {
        if (-not $sp) {
            Write-Host -Object "$($_.PSChildName)  $($name)"
        }
        else {
            Write-Host -Object "$($_.PSChildName)  $($name) SP$($sp)"
        }
}
    if (-not $name) {
        $parentName = $_.PSChildName
        Get-ChildItem -LiteralPath $_.PSPath |
        Where-Object {
            if ($_.Property -contains 'Version') { $name = Get-ItemPropertyValue -Path $_.PSPath -Name Version }
            if ($name -and ($_.Property -contains 'SP')) { $sp = Get-ItemPropertyValue -Path $_.PSPath -Name SP }
            if ($_.Property -contains 'Install') { $install = Get-ItemPropertyValue -Path $_.PSPath -Name Install }
            if (-not $install) {
                Write-Host -Object "  $($parentName)  $($name)"
            }
            elseif ($install -eq '1') {
                if (-not $sp) {
                    Write-Host -Object "  $($_.PSChildName)  $($name)"
                }
                else {
                    Write-Host -Object "  $($_.PSChildName)  $($name) SP$($sp)"
                }
            }
        }
    }
}

Проверка минимальной версии:

(Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge 394802

Текущая версия через dotnet:

dotnet
dotnet --version
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes

Полезные ссылки

03.05.2024

Категория(-и): Статьи

Comments are closed.