GIMP is a free and open-source raster graphics editor used for image retouching and editing, free-form drawing, converting between different image formats, and more specialized tasks.
PowerShell logging is turned on and will write to %ProgramData%\Software.
Removes any version of GIMP, whether 32 or 64-bit. A variable array is used to ensure both Program Files locations are checked. Variables are also used to determine the name of the program folder and the program executable as these items are version-specific. A variable is also used to determine the name of the uninstaller executable, as this can vary between unins000.exe and unins001.exe, depending upon how many times the software has been previously installed and removed.
Uninstall.ps1
# This script performs the installation or uninstallation of an application(s).
# Created 29/07/2019 | cru2.io
# Variables
[string]$CurrentPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
[string]$appLogPath = "$env:ProgramData\Software"
If (!(Test-Path $appLogPath))
{New-Item -ItemType Directory $appLogPath -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null}
Start-Transcript -Path "$appLogPath\GIMP Universal Uninstaller.log" -Append
# Remove previous versions if exist
Write-Host "Check for and uninstall previous versions of GIMP (32 or 64-bit)"
# Install directory ends in a variable number which must be checked
[array]$appFolders = ${env:ProgramFiles(x86)},$env:ProgramFiles
ForEach ($appFolder in $appFolders)
{
# Get full path
$appDir = 'GIMP*'
$appPath = dir -Path $appFolder -Filter $appDir -Force -ErrorAction SilentlyContinue | %{$_.FullName}
If ($appPath -ne $null)
{
# EXE filename ends in a variable number which must be checked
# This file is checked solely to log the versions found before removal
$appEXE = 'gimp-console-*.exe'
$appFiles = dir -Path "$appPath\bin" -Filter $appEXE -Force -ErrorAction SilentlyContinue | %{$_.FullName}
ForEach ($appFile in $appFiles)
{
If ($appFile -ne $null)
{
$OldVersion = (Get-Item $appFile).VersionInfo.FileVersion
}
}
# EXE uninstall filename ends in a variable number which must be checked
$UninstEXE = 'unins*.exe'
$Uninst = dir -Path "$appPath\uninst" -Filter $UninstEXE -Force -ErrorAction SilentlyContinue | %{$_.FullName}
ForEach ($UninstFile in $Uninst)
{
If ($UninstFile -ne $null)
{
Write-Host "Uninstalling GIMP $OldVersion"
Start-Process $UninstFile -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait -PassThru -NoNewWindow -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
Sleep 5
Remove-Item $appPath -Recurse -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
}
}
}
Stop-Transcript | Out-Null