From 54bd026bd827d4b1e07fbd3d8c8108b318236530 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Tue, 4 Jun 2019 10:02:52 -0700 Subject: [PATCH] replace wmiobject with gci uninstall reg --- RemoveCoreSDKs.ps1 | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/RemoveCoreSDKs.ps1 b/RemoveCoreSDKs.ps1 index 9abb0f2..132b844 100644 --- a/RemoveCoreSDKs.ps1 +++ b/RemoveCoreSDKs.ps1 @@ -1,11 +1,21 @@ -$app = Get-WmiObject -Class Win32_Product | Where-Object { - $_.Name -match "Microsoft .NET Core SDK" -} +[CmdletBinding()] + param ( + $DisplayName = "Microsoft .NET Core SDK" + ) -Write-Host $app.Name -Write-Host $app.IdentifyingNumber -pushd $env:SYSTEMROOT\System32 + $VerbosePreference = "Continue" -$app.identifyingnumber |% { Start-Process msiexec -wait -ArgumentList "/x $_" } + $apps = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ` + Where-Object { $_.DisplayName -match $DisplayName } -popd + foreach ($app in $apps) { + + $exepath = $app.QuietUninstallString.Substring(1, $app.QuietUninstallString.LastIndexOf("`"")-1) + $exeargs = $app.QuietUninstallString.Substring($app.QuietUninstallString.LastIndexOf("`"")+2) + + if (Test-Path $exepath) { + + Write-Verbose "Uninstalling $($app.DisplayName)..." + Start-Process -FilePath $exepath -ArgumentList $exeargs -Wait -NoNewWindow -PassThru + } + }