Created
March 11, 2020 20:00
-
-
Save deviousasti/a96051f7520898aa5eb99910935a0e21 to your computer and use it in GitHub Desktop.
Cleanup DotNetSdk
This file contains 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
# Discussion at https://github.com/dotnet/sdk/issues/2295 | |
function Uninstall-DotNetSdk { | |
param ( | |
[parameter(Mandatory = $False)] [switch] $All, | |
[parameter(Mandatory = $False)] [switch] $WhatIf | |
) | |
pushd $env:SystemRoot\System32 | |
Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | | |
Get-ItemProperty | | |
Where-Object DisplayName -match "^Microsoft .NET Core SDK" | | |
Where-Object BundleVersion -match "^\d+\.\d+\.\d+\d\d\.\d+$" | | |
Group-Object { ([regex] "^(\d+\.\d+\.\d+)\d\d\.\d+$").Match($_.BundleVersion).Groups[1].Value } | | |
Sort-Object { [regex]::Replace($_.Name, '\d+', { param($match) $match[0].Value.PadLeft(10,'0') }) } | | |
ForEach-Object { | |
$_.Group | | |
Sort-Object { | |
$versionMatch = ([regex] "^\d+\.\d+\.\d+(\d\d)\.(\d+)$").Match($_.BundleVersion) | |
$v1 = $versionMatch.Groups[1].Value | |
$v2 = $(if ($versionMatch.Groups[2].Value -eq "0") { "9".PadLeft(10,'9') } else { $versionMatch.Groups[2].Value.PadLeft(10,'0') }) | |
"$v1.$v2" | |
} | | |
Select-Object -SkipLast $(if ($All) { 0 } else { 1 }) | | |
ForEach-Object { | |
if ($_.QuietUninstallString -imatch '^"?([^"]+)"? +(/uninstall.*)$') { | |
$file = $Matches[1] | |
$arglist = $Matches[2] | |
"Uninstall command: `"$file`" $arglist" | |
if (-not $WhatIf) { Start-Process -FilePath $file -ArgumentList $arglist -Wait } | |
} | |
} | |
} | |
popd | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment