Skip to the road
Adminpatchlog

Windows & PowerShell

PowerShell Remote Uninstalls: Find, Remove and Verify Windows Apps

William Garcia 907 travellers

Identify the right MSI, remove it remotely in a pilot, and map exit codes to follow-up actions. Use PDQ when WinRM isn’t available.

PowerShell Remote Uninstalls: Find, Remove and Verify Windows Apps

Remote software removal depends on getting two things right: identifying the exact installation and running its uninstaller in the correct user context. A repeatable PowerShell process can remove machine-wide MSI apps across Windows devices, while a pilot and post-removal checks help catch mismatches before a wider rollout.

ConnectIcon CTA

Identify the installed product before removal

Check both machine-wide uninstall registry locations. 64-bit applications typically register under HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall; 32-bit applications typically use HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall. MSI installations use the product GUID as the registry key name, while other installers may follow different naming conventions.

Match the application’s DisplayName, Publisher, version and, for MSI software, product code. A broad wildcard can select the wrong entry. This discovery example checks both registry paths on a list of remote computers and returns matching machine-wide MSI registrations:

$cred = Get-Credential

Invoke-Command -ComputerName (Get-Content .\targets.txt) -Credential $cred `
    -ScriptBlock {
    Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
        'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
        Where-Object { $_.DisplayName -eq 'Example App' -and
            $_.Publisher -eq 'Example Corp' -and $_.WindowsInstaller -eq 1 } |
        Select-Object DisplayName, DisplayVersion, PSChildName
}

Avoid using WMI’s Win32_Product class for discovery. Microsoft describes it as slow and notes that it can trigger verification and repair activity, which may have side effects.

For MSI software, the quiet uninstall command is msiexec /x "{ProductCode}" /qn /norestart. Third-party EXE installers need their own silent switches; confirm the vendor-specific command before deploying it. A silent MSI removal can close the application without prompting, so set a maintenance window and ask users to save their work.

Run a pilot through WinRM

Before running a removal remotely, confirm WinRM is configured on the clients and that the credentials have the required access. Use a representative pilot group first. The following example runs the MSI uninstall on computers listed in pilot.txt, records the exit code and status, and appends results to a CSV log:

$code = '{11111111-2222-3333-4444-555555555555}'
$log = foreach ($pc in Get-Content .\pilot.txt) {
    try {
        $exit = Invoke-Command -ComputerName $pc -Credential $cred `
            -ErrorAction Stop -ScriptBlock {
            (Start-Process msiexec.exe `
                -ArgumentList "/x $using:code /qn /norestart" `
                -Wait -PassThru).ExitCode
        }
        $state = switch ($exit) {
            0                    { 'Verify' }
            { $_ -in 3010, 1641 } { 'RestartRequired' }
            1605                 { 'AbsentInContext' }
            1618                 { 'Retry' }
            default              { 'Failed' }
        }
    } catch { $exit = $null; $state = 'Unreachable' }
    [pscustomobject]@{
        Computer = $pc; Product = $code; ExitCode = $exit
        State = $state; Time = Get-Date -Format s
    }
}
$log | Export-Csv .\uninstall-log.csv -Append -NoTypeInformation

The script assigns each result a state to guide follow-up. “Unreachable” means the host may be offline, WinRM may be unavailable, the network path may be missing or the credentials may be wrong. Fix the connection issue before retrying.

Exit code 1605 means the product isn’t installed in the context used for the uninstall. Check the product code; if it’s correct, the app may be installed per user and unavailable to the remoting account. Code 1618 means another installation is in progress, so retry later.

Codes 3010 and 1641 indicate a successful removal with restart implications. For 3010, schedule a restart and verify afterward; for 1641, wait for the initiated restart to finish before checking. Code 0 is a successful uninstall that still needs verification. Other codes, such as 1603, indicate an unhandled failure; check the Windows Installer error codes and rerun with /l*v to capture an MSI log if needed.

Confirm the registration is gone

After the pilot, check both registry locations for the product code. A remaining entry means the removal needs investigation; an absent entry confirms the registration is gone, though teams should also review their software inventory to confirm the device’s reported state.

Invoke-Command -ComputerName (Get-Content .\pilot.txt) -Credential $cred `
    -ScriptBlock {
    Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$using:code",
        "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$using:code"
}

Use PDQ when WinRM isn’t suitable

PDQ can deliver a tested uninstall command through its agent to devices that are reachable over the internet without a VPN. Offline devices are queued until they reconnect. Its Uninstall It All template, available through the Package Library, can find an application and attempt its removal. Duplicate the package to edit its parameters, then run it with -AuditOnly to confirm the app’s exact name. Replace that parameter with the quoted name, such as "Example App", and deploy to a pilot group before expanding the rollout.

For a custom MSI package, add a PowerShell script step that returns the installer’s exit code:

$code = '{11111111-2222-3333-4444-555555555555}'
$process = Start-Process -FilePath 'msiexec.exe' `
    -ArgumentList "/x $code /qn /norestart" `
    -Wait -PassThru -ErrorAction Stop
exit $process.ExitCode

In the package’s Success codes, include 0, 3010 and 1641 so successful removals and restart cases are recorded as success. Keep Run as set to Local System for machine-wide apps. For per-user installations that return 1605 under the system account, use Logged on User; that user must be signed in locally, not through Remote Desktop. Target a device group based on PDQ software inventory, then review and rescan the pilot devices after deployment.

Per-user apps and package-provider limits

Uninstall-Package relies on the package provider. The built-in Programs provider can list some EXE-installed software through Get-Package, but it doesn’t reliably remove those apps. Use the installer’s own uninstall command instead.

Per-user software can be removed remotely when the uninstaller runs as the account that owns the installation. For per-user MSI installs, use the product code with msiexec /x "{ProductCode}" /qn /norestart. In PDQ, choose Logged on User while that user is signed in locally. Keep the rollout staged, and use the logged results and inventory rescan to decide when the broader deployment is ready.

Source: William Garcia · www.pdq.com

On the same route