如何通过Powershell找到安装哪个dotnet Framework版本?
我发现some code但是它无效,或者我不知道如何运行它。
你能帮我开发一下可以在cmd
上运行并收集.Net框架版本的脚本吗?
答案 0 :(得分:2)
您的链接问题中的PowerShell代码出错,这里是它的工作版本,它提供了这样的输出:
v2.0.50727 2.0.50727.4927 SP 2 v3.0 3.0.30729.4926 SP 2 v3.5 3.5.30729.4926 SP 1 v4 Client 4.6.01586 v4 Full 4.6.01586 v4.0 Client 4.0.0.0
function Get-KeyPropertyValue($key, $property) {
if ($key.Property -contains $property) {
Get-ItemProperty $key.PSPath -name $property | Select-Object -expand $property
}
}
function Get-VersionName($key) {
$name = Get-KeyPropertyValue $key Version
$sp = Get-KeyPropertyValue $key SP
if ($sp) {
"$($_.PSChildName) $name SP $sp"
}
else {
"$($_.PSChildName) $name"
}
}
function Get-FrameworkVersion {
Get-ChildItem "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\" | Where-Object {$_.PSChildName -like "v*"} | ForEach-Object {
if ( $_.Property -contains "Version") {
Get-VersionName $_
}
else {
$parent = $_
Get-ChildItem $_.PSPath | ForEach-Object {
$versionName = Get-VersionName $_
"$($parent.PSChildName) $versionName"
}
}
}
}
Get-FrameworkVersion
修改强>
if (Test-Path "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full") {
switch (Get-KeyPropertyValue (Get-Item $v4Directory) Release) {
378389 {".NET Framework 4.5"; break; }
378675 {".NET Framework 4.5.1 installed with Windows 8.1 or Windows Server 2012 R2"; break; }
378758 {".NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2"; break; }
379893 {".NET Framework 4.5.2"; break; }
{ 393295, 393297 -contains $_} {".NET Framework 4.6"; break; }
{ 394254, 394271 -contains $_} {".NET Framework 4.6.1"; break; }
{ 394802, 394806 -contains $_} {".NET Framework 4.6.2"; break; }
}
}