Skip to content

Instantly share code, notes, and snippets.

@mortenya
Created September 21, 2016 20:40
Show Gist options
  • Save mortenya/e1601d4ff5607e06467d12022973eb8b to your computer and use it in GitHub Desktop.
Save mortenya/e1601d4ff5607e06467d12022973eb8b to your computer and use it in GitHub Desktop.
There was no universal uninstaller for the GroupWise client that functioned the way we needed, so this script will simply find the installation in the registry and run the uninstall via MSIEXEC.
if (Test-Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall) {
$gwreg = Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | foreach {
Get-ItemProperty $_.pspath | where {
$_.DisplayName -like '*GroupWise*'
}
}
}
else {
$gwreg = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | foreach {
Get-ItemProperty $_.pspath | where {
$_.DisplayName -like '*GroupWise*'
}
}
}
foreach ($gw in $gwreg) {
Write-Verbose "Removing version $($gw.DisplayVersion) of $($gw.DisplayName)"
Add-Content -Value "$(Get-Date)" -Path C:\LOGS\GWUninstall.log
Add-Content -Value "Attempting to remove version $($gw.DisplayVersion) of $($gw.DisplayName)" -Path C:\LOGS\GWUninstall.log
Add-Content -Value "`tMSI Key: $($gw.PSChildName)" -Path C:\LOGS\GWUninstall.log
Add-Content -Value "`r`n" -Path C:\LOGS\GWUninstall.log
$arguments = "/X$($gw.PSChildName) /qn /norestart /Limew `"C:\LOGS\$($gw.DisplayName).log`""
$process = Start-Process -FilePath "C:\Windows\System32\msiexec.exe" -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -eq 1639) {
Add-Content -Value "Error 1639 - ERROR_INVALID_COMMAND_LINE" -Path C:\LOGS\GWUninstall.log
Add-Content -Value "Attempt #2 to remove version $($gw.DisplayVersion) of $($gw.DisplayName)" -Path C:\LOGS\GWUninstall.log
Add-Content -Value "`r`n" -Path C:\LOGS\GWUninstall.log
$arguments = "/X$($gw.PSChildName) /qn /norestart /Limew C:\LOGS\gw-pull.log"
$process = Start-Process -FilePath "C:\Windows\System32\msiexec.exe" -ArgumentList $arguments -Wait -PassThru
}
if ($process.ExitCode -eq 0) {
Add-Content -Value "SUCCESS - Uninstall completed... :)" -Path C:\LOGS\GWUninstall.log
}
else {
Add-Content -Value "FAILED - Something went wrong! :(" -Path C:\LOGS\GWUninstall.log
}
Add-Content -Value "`r`n" -Path C:\LOGS\GWUninstall.log
}
# http://stackoverflow.com/questions/4124409/run-msiexec-from-powershell-and-get-return-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment