fleet/ee/maintained-apps/inputs/winget/scripts/docker_uninstall.ps1
Jahziel Villasana-Espinoza 658a298d5a
more fixes for FMA windows ingestion (#27487)
> For #26662

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [x] Manual QA for all new/changed functionality
2025-03-27 17:43:40 -04:00

55 lines
1.5 KiB
PowerShell

# Define acceptable/expected exit codes
$ExpectedExitCodes = @(0, 19)
# Uninstall Registry Key
$machineKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Docker Desktop'
# Initialize exit code
$exitCode = 0
try {
$key = Get-ItemProperty -Path $machineKey -ErrorAction Stop
# Get the uninstall command. Some uninstallers do not include 'QuietUninstallString'
$uninstallCommand = if ($key.QuietUninstallString) {
$key.QuietUninstallString
} else {
$key.UninstallString
}
# The expected uninstall command value is "C:\Program Files\Docker\Docker\Docker Desktop Installer.exe" "uninstall"
$splitArgs = $uninstallCommand.Split('"')
if ($splitArgs.Length -ne 5) {
Throw "Unexpected uninstall command. Please update the uninstall script.`nUninstall command: $uninstallCommand"
}
$uninstallCommand = $splitArgs[1]
$uninstallArgs = $splitArgs[3]
Write-Host "Uninstall command: $uninstallCommand"
Write-Host "Uninstall args: $uninstallArgs"
$processOptions = @{
FilePath = $uninstallCommand
PassThru = $true
Wait = $true
}
if ($uninstallArgs -ne '') {
$processOptions.ArgumentList = "$uninstallArgs"
}
# Start uninstall process
$process = Start-Process @processOptions
$exitCode = $process.ExitCode
Write-Host "Uninstall exit code: $exitCode"
} catch {
Write-Host "Error: $_"
$exitCode = 1
}
# Treat acceptable exit codes as success
if ($ExpectedExitCodes -contains $exitCode) {
Exit 0
} else {
Exit $exitCode
}