Recently, I decided to make a Powershell script that will make it easier for larger environments to uninstall and upgrade software. This is a continuation of the script that I wrote a while back ago that can find uninstall strings for 32 and 64bit applications (Link). Similar to the previous script, this script will automatically find the uninstall string for the specified program, but now it will also uninstall the program and install an upgraded version with the install file that you picked.
Here is everything you will need to configure for this script to work:
The following 3 variables must be used:
$appname = YOUR APPLICATION NAME
$uninstallswitches = YOUR UNINSTALL SWITCHES
$installswitches = YOUR INSTALL SWITCHES
The following variable is not mandatory but you can add it if you need to:
$transformfile = TRANSFORM/MST FILE GOES HERE
You will only need to specify one of the following variables:
$MSIfile = MSI FILE GOES HERE (EXAMPLE: C:\INSTALLS\SETUP.MSI)
$EXEfile= EXE FILE GOES HERE (EXAMPLE: C:\INSTALLS\SETUP.EXE)
Please keep in mind this is version 1 of the tool. If you have any issues, please feel free to comment below or send me a message from the contact page!
A download for this script can be found at the bottom of this post.
#Customizable Information #The appname variable cannot be empty, please insert name of software $appname = "" #Insert your uninstall and install silent switches below $uninstallswitches = "" $installswitches = "" #If you are using an MSI file please insert the location of the file in the MSIFile variable. Please insert all EXE installs into the EXEfile variable $MSIfile = "" $EXEfile = "" #Insert your transform file location in the transformfile variable. This is not a required field $transformfile = "" if ($transformfile) { $transforms = "TRANSFORMS=`"$transformfile`"" } else { $transforms = "" } $toolversion = "V1" if ($MSIfile -or $EXEfile) { if ($appname) { #Retrieves Uninstall Strings $32bit = get-itemproperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, UninstallString, PSChildName | Where-Object { $_.DisplayName -match "^*$appname*"} $64bit = get-itemproperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, UninstallString, PSChildName | Where-Object { $_.DisplayName -match "^*$appname*"} if ($MSIfile) { $filecheck = Test-Path -LiteralPath "$MSIfile" if($filecheck -eq $true) { #IF YOU SPECIFIED AN MSI INSTALL FILE if ($64bit -eq "" -or $64bit.count -eq 0) { switch ($32bit.DisplayName.count) { 0 { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } 1 { if ($32bit -match "msiexec.exe") { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $32bit.UninstallString -replace 'msiexec.exe /i','msiexec.exe /x' cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } else { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $32bit.UninstallString cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } } default { Write-Host "Found multiple installations" -ForegroundColor Red exit } } } else { switch ($64bit.DisplayName.count) { 0 { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } 1 { if ($64bit -match "msiexec.exe") { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $64bit.UninstallString -replace 'msiexec.exe /i','msiexec.exe /x' cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } else { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $64bit.UninstallString cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "msiexec.exe" -ArgumentList "/i `"$MSIfile`" $transforms $installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } } default { Write-Host "Found multiple installations." -ForegroundColor Red exit } } } } else { Clear-Host Write-Host "Error - Cannot find your MSI file" -ForegroundColor Red } } else { $filecheck = Test-Path -LiteralPath "$EXEfile" if($filecheck -eq $true) { #IF YOU SPECIFIED AN EXE INSTALL FILE if ($64bit -eq "" -or $64bit.count -eq 0) { switch ($32bit.DisplayName.count) { 0 { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } 1 { if ($32bit -match "msiexec.exe") { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $32bit.UninstallString -replace 'msiexec.exe /i','msiexec.exe /x' cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } else { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $32bit.UninstallString Start-Process -Filepath "$uninstall" -ArgumentList "$uninstallswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } } default { Write-Host "Found multiple installations" -ForegroundColor Red exit } } } else { switch ($64bit.DisplayName.count) { 0 { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } 1 { if ($64bit -match "msiexec.exe") { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $64bit.UninstallString -replace 'msiexec.exe /i','msiexec.exe /x' cmd /c ("$uninstall" + ' ' + $uninstallswitches) Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } else { Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname" $uninstall = $64bit.UninstallString Start-Process -Filepath "$uninstall" -ArgumentList "$uninstallswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" Start-Sleep -s 4 Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname" Start-Process -Filepath "$EXEfile" -ArgumentList "$installswitches" -wait Clear-Host Write-Host "***Uninstall and Install Tool $toolversion***" -ForegroundColor Green; Write-Host "***********************************" -ForegroundColor Green; Write-Host "Uninstalling $appname - Done" ; Write-Host "Installing $appname - Done" Start-Sleep -s 4 } } default { Write-Host "Found multiple installations." -ForegroundColor Red exit } } } } else { Clear-Host Write-Host "Error - Cannot find EXE file" -ForegroundColor Red } } } else { Clear-Host Write-Host "Error - Appname variable is empty." -ForegroundColor Red } } else { Clear-Host Write-Host "Error - Please provide install file in the MSIfile or EXEfile variable" -ForegroundColor Red }
Download the .ps1 below:
Download Now
Edward W.
Is it normal for this script to hang for more than a few minutes at a time?
Thanks,
Edward-
Jose Espitia
This is such an old script of mine. The script hanging may be caused by the parameters that you set to install or uninstall an application. I plan on revamping this script and make it easier to use by creating a function for uninstalls and a function for installs.
Jorge
Can you please tell me the the install/uninstall switches or point a site where i can find it?
Jose Espitia
Every application is different. You should reach out to the vendor of the app to receive that information.