Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $appname = "Google Chrome"
- $paths = @(
- 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
- 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
- );
- $tempPaths = @();
- foreach ($path in $paths) {
- if (Test-Path -Path $path) {
- $tempPaths += $path;
- };
- };
- $paths = $tempPaths;
- $app = Get-ItemProperty $paths | Where-Object DisplayName -eq $appname | Select-Object -first 1;
- if ($null -ne $app) {
- Write-Output "Found $appname in installed software.";
- $app;
- } else {
- Throw "$appname not found";
- };
- # End Detection
- # Start Uninstall
- if ($null -ne $app) {
- $app;
- Write-Host "Starting appname uninstall";
- $guid = $app.PSChildName.trim("{}");
- $hasGuid = $false;
- Try {
- [System.Guid]::Parse($guid);
- $hasGuid = $true;
- } Catch {
- Write-Host "Invalid GUID: $($app.PSChildName)";
- $hasGuid = $false;
- };
- if ($hasGuid) {
- Write-Host "Running command: msiexec /x $($app.PSChildName) /qn";
- $proc = Start-Process -FilePath msiexec -Wait -PassThru -ArgumentList "/x", $app.PSChildName, "/qn";
- } else {
- Write-Host "Found uninstall string";
- $uninstallString = $app.UninstallString.split('"')[1];
- $arguments = $app.UninstallString.split('"')[2].split(" ");
- $arguments += "--force-uninstall";
- $arguments = $arguments[1..($arguments.Length - 1)];
- Write-Host "Running command: $uninstallString $arguments";
- $proc = Start-Process -FilePath $uninstallString -Wait -PassThru -ArgumentList $arguments;
- };
- Write-Host "Uninstall exited with code: $($proc.ExitCode)";
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement