Trying to Create an MSI Uninstaller using PSADT

Hello Folks, I am trying to use psadt to unintalling Beyond trust modules which were installed using msi setup.However when i run psadt it says its unable to find those msi even with msi installed and can be seen in HKLM uninstall path.

Can you post the line you are using to uninstall the MSI?

I am using below command line in pre-install step
Uninstall-ADTApplication -Name 'Privilege Management for Windows*' -ApplicationType 'MSI' -FilterScript { $_.Publisher -match 'BeyondTrust Corporation' } start-sleep 20

Uninstall-ADTApplication -Name 'BeyondTrust Privilege Management Cloud Adapter (x64)' -ApplicationType 'MSI' -FilterScript { $_.Publisher -match 'BeyondTrust Corporation' } start-sleep 20

Uninstall-ADTApplication -Name 'BeyondTrust Privilege Management Package Manager (x64)' -ApplicationType 'MSI' -FilterScript { $_.Publisher -match 'BeyondTrust Corporation' } start-sleep 15

Below is what is shows up in logging:

<![LOG[[Initialization] :: Current process is running under a system account [NT AUTHORITY\SYSTEM].]LOG]!><time="06:45:04.493-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: The following user is the console user [AzureAD\JoshBrownhill] (user with control of physical monitor, keyboard, and mouse).]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: The active logged on user who will receive UI elements is [AzureAD\JoshBrownhill].]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: The current execution context has a primary UI language of [en-US].]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: The following locale was used to import UI messages from the strings.psd1 files: [en-US].]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Unable to find COM object [Microsoft.SMS.TSEnvironment]. Therefore, script is not currently running from a SCCM Task Sequence.]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Device has completed the OOBE and toolkit is not running with an active ESP in progress.]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Session 0 detected, user(s) logged on to interact if required.]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: No processes were specified as requiring closure.]LOG]!><time="06:45:04.509-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Installation is running in [Interactive] mode.]LOG]!><time="06:45:04.523-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Deployment type is [Install].]LOG]!><time="06:45:04.523-480" date="11-26-2025" component="Open-ADTSession" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Initialization] :: Module [PSAppDeployToolkit.Extensions] imported successfully.]LOG]!><time="06:45:04.666-480" date="11-26-2025" component="PSAppDeployToolkit.Extensions.psm1" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit.Extensions\PSAppDeployToolkit.Extensions.psm1">
<![LOG[[Pre-Install] :: Creating the progress dialog in a separate thread with [StatusMessage: Installation in progress. Please wait…], [StatusMessageDetail: This window will close automatically when the installation is complete.].]LOG]!><time="06:45:05.167-480" date="11-26-2025" component="Show-ADTInstallationProgress" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Instantiating user client/server process.]LOG]!><time="06:45:05.183-480" date="11-26-2025" component="Invoke-ADTClientServerOperation" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Getting information for installed applications matching the provided FilterScript...]LOG]!><time="06:45:06.791-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Found no application based on the supplied FilterScript.]LOG]!><time="06:45:06.858-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: No applications found for removal.]LOG]!><time="06:45:06.905-480" date="11-26-2025" component="Uninstall-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Getting information for installed applications matching the provided FilterScript...]LOG]!><time="06:45:26.942-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Found no application based on the supplied FilterScript.]LOG]!><time="06:45:26.958-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: No applications found for removal.]LOG]!><time="06:45:26.976-480" date="11-26-2025" component="Uninstall-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Getting information for installed applications matching the provided FilterScript...]LOG]!><time="06:45:47.016-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: Found no application based on the supplied FilterScript.]LOG]!><time="06:45:47.025-480" date="11-26-2025" component="Get-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Pre-Install] :: No applications found for removal.]LOG]!><time="06:45:47.037-480" date="11-26-2025" component="Uninstall-ADTApplication" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Post-Install] :: Displaying custom installation prompt asynchronously to [AzureAD\JoshBrownhill] with message: [You can customize text to appear at the end of an install or remove it completely for unattended installations.].]LOG]!><time="06:46:02.261-480" date="11-26-2025" component="Show-ADTInstallationPrompt" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Finalization] :: Closing the installation progress dialog.]LOG]!><time="06:46:03.665-480" date="11-26-2025" component="Close-ADTInstallationProgress" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Finalization] :: Closing user client/server process.]LOG]!><time="06:46:03.799-480" date="11-26-2025" component="Close-ADTClientServerProcess" context="NT AUTHORITY\SYSTEM" type="1" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[[Finalization] :: [BeyondTrustCorporation_BeyondTrust-Uninstaller_Beta_x64_EN_01] install completed in [59.9680407] seconds with exit code [0].]LOG]!><time="06:46:04.399-480" date="11-26-2025" component="Close-ADTSession" context="NT AUTHORITY\SYSTEM" type="0" thread="5624" file="C:\WINDOWS\IMECache\7acf8a75-34c8-4d23-84cf-d28e4c69203b_1\PSAppDeployToolkit\PSAppDeployToolkit.psm1">
<![LOG[-------------------------------------------------------------------------------]LOG]

The thing that is common across all three is

... $_.Publisher -match 'BeyondTrust Corporation' ...

:thinking:
I'm wondering if it is not finding the apps because this Publisher name does not match.

This is a little left field...
Prior to PSADT 4.x I sometimes used the following PowerShell function to gather uninstall info for installed apps (thanks to Cheatsheet for PSAppDeployToolkit – SIMSEN blog):

function Get-Uninstaller {
  [CmdletBinding()]
  param(
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [string] $Name
  )
 
  $local_key     = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
  $machine_key32 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
  $machine_key64 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
 
  $keys = @($local_key, $machine_key32, $machine_key64)
 
  Get-ItemProperty -Path $keys -ErrorAction 'SilentlyContinue' | ?{ ($_.DisplayName -like "*$Name*") -or ($_.PsChildName -like "*$Name*") } | Select-Object PsPath,DisplayVersion,DisplayName,UninstallString,InstallSource,InstallLocation,QuietUninstallString,InstallDate
}

I can see your script is being run as SYSTEM (according to the 1st line of your log), So I wonder if you ran the above function on one of your machines with this software installed on as system (psexec -s etc...) would give you some other insights.

N.B. You would need to use the function something like:
Get-Uninstaller Privilege
It 'should' return the uninstall information for each of the 3 apps (and maybe others if they contain 'Privilege' in the name)
This might help you identify something different about the uninstallers for these apps

Hello Adrian, Thanks for reaching back.I did run the function with publisher filed added and it turns the value is correct.

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{423343BB-49F1-4F19-A62B-9128A4263F4E}
DisplayVersion : 25.5.440
DisplayName : BeyondTrust Privilege Management Cloud Adapter (x64)
UninstallString : MsiExec.exe /X{423343BB-49F1-4F19-A62B-9128A4263F4E}
InstallSource : C:\Beyond Trust-25.4\Files
InstallLocation :
QuietUninstallString :
InstallDate : 20251126
Publisher : BeyondTrust Corporation

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{590a0961-bac2-482c-9c30-d56910c4489e}
DisplayVersion : 25.4.221.0
DisplayName : Privilege Management for Windows (x64) 25.4.221.0
UninstallString : MsiExec.exe /X{590a0961-bac2-482c-9c30-d56910c4489e}
InstallSource : C:\Beyond Trust-25.4\Files
InstallLocation : C:\Program Files\Avecto\Privilege Guard Client
QuietUninstallString :
InstallDate : 20251126
Publisher : BeyondTrust Corporation

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{61F8F2CC-9CDB-4C1B-B0BD-5067ACCF22DB}
DisplayVersion : 25.7.509
DisplayName : BeyondTrust Privilege Management Package Manager (x64)
UninstallString : MsiExec.exe /X{61F8F2CC-9CDB-4C1B-B0BD-5067ACCF22DB}
InstallSource : C:\ProgramData\Avecto\Downloads
InstallLocation :
QuietUninstallString :
InstallDate : 20251126
Publisher : BeyondTrust Corporation

Initally i though that msi was installed as user based and system was not able to read it.But after checking HKLM regs and control panel from different profiles it got cleared that it was system wide.

I wonder if you simplify your uninstall commands to something like this (definitely remove the start-sleep as that is not a valid parameter to pass to the Uninstall-ADTApplication function) and also possibly remove the -FilterScript

Uninstall-ADTApplication -Name 'Privilege Management for Windows' -ApplicationType 'MSI'

Uninstall-ADTApplication -Name 'Privilege Management Cloud Adapter' -ApplicationType 'MSI'

Uninstall-ADTApplication -Name 'Privilege Management Package Manager' -ApplicationType 'MSI'

I have shortened the -Name content for each one as the -Name switch "Performs a contains match on the application display name by default.", so it does not have to be exact, see:

1 Like
## removes any chrome installation if installed
    $previouschrome = (Get-ADTApplication -Name 'Google Chrome')
    if ($previouschrome -ne $null){   
    Write-ADTLogEntry -Message "$($adtSession.Appvendor, $adtSession.Appname) previous version detected. Uninstalling."
    Uninstall-ADTApplication -InstalledApplication $previouschrome `
    -LogFileName "$($adtSession.Appvendor, $adtSession.Appname) Previous Version" `
    -ArgumentList '/QN /noreboot'}
    
    else{
    Write-ADTLogEntry -Message "No previous versions detected. Moving onto Pre-Requisites stage"}

I use the above to target previous installs of apps i need to regularly update. Works well for .exe's as well. Just change the arguments and omit the log cmd.

1 Like

I wonder if this is the issue here. When i ran the function to get uninstaller string below is the output

get-uninstaller privilege

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
\Uninstall{423343BB-49F1-4F19-A62B-9128A4263F4E}
DisplayVersion : 25.5.440
DisplayName : BeyondTrust Privilege Management Cloud Adapter (x64)
UninstallString : MsiExec.exe /X{423343BB-49F1-4F19-A62B-9128A4263F4E}
InstallSource : C:\Beyond Trust-25.4\Files
InstallLocation :
QuietUninstallString :
InstallDate : 20251128

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
\Uninstall{590a0961-bac2-482c-9c30-d56910c4489e}
DisplayVersion : 25.4.221.0
DisplayName : Privilege Management for Windows (x64) 25.4.221.0
UninstallString : MsiExec.exe /X{590a0961-bac2-482c-9c30-d56910c4489e}
InstallSource : C:\Beyond Trust-25.4\Files
InstallLocation : C:\Program Files\Avecto\Privilege Guard Client
QuietUninstallString :
InstallDate : 20251128

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
\Uninstall{61F8F2CC-9CDB-4C1B-B0BD-5067ACCF22DB}
DisplayVersion : 25.7.509
DisplayName : BeyondTrust Privilege Management Package Manager (x64)
UninstallString : MsiExec.exe /X{61F8F2CC-9CDB-4C1B-B0BD-5067ACCF22DB}
InstallSource : C:\ProgramData\Avecto\Downloads
InstallLocation :
QuietUninstallString :
InstallDate : 20251128

But when i used below command, i got below output
$Installer = New-Object -ComObject WindowsInstaller.Installer; $InstallerProducts = $Installer.ProductsEx("", "", 7); $InstalledProducts = ForEach($Product in $InstallerProducts){[PSCustomObject]@{ProductCode = $Product.ProductCode(); LocalPackage = $Product.InstallProperty("LocalPackage"); VersionString = $Product.InstallProperty("VersionString"); ProductPath = $Product.InstallProperty("ProductName")}} $InstalledProducts

ProductCode LocalPackage VersionString ProductPath


{0025DD72-A959-45B5-A0A3-7EFEB15A8050} C:\WINDOWS\Installer\133635.msi 14.36.32532 Microsoft Visual C++ 2022 X6...
{1FC1A6C2-576E-489A-9B4A-92D21F542136} C:\WINDOWS\Installer\10e642.msi 3.74.0.0 Microsoft Update Health Tools
{6070BE95-B84D-40FE-8ABD-C70B59F5A164} C:\WINDOWS\Installer\133638.msi 12.4.5.23787635 VMware Tools
{85C69797-7336-4E83-8D97-32A7C8465A3B} C:\WINDOWS\Installer\10e63e.msi 8.94.0.0 Update for Windows 10 for x6...
{e4a2bae8-4a42-4610-a00b-72df6baf2ab8} C:\WINDOWS\Installer\47200.msi 25.4.270.0 Privilege Management for Win...
{C2C59CAB-8766-4ABD-A8EF-1151A36C41E5} C:\WINDOWS\Installer\13362d.msi 14.36.32532 Microsoft Visual C++ 2022 X8...
{423343BB-49F1-4F19-A62B-9128A4263F4E} C:\WINDOWS\Installer\4e51c26.msi 25.5.440 BeyondTrust Privilege Manage...
{61F8F2CC-9CDB-4C1B-B0BD-5067ACCF22DB} C:\WINDOWS\Installer\47073.msi 25.7.509 BeyondTrust Privilege Manage...
{73F77E4E-5A17-46E5-A5FC-8A061047725F} C:\WINDOWS\Installer\133629.msi 14.36.32532 Microsoft Visual C++ 2022 X8...
{750D7D5E-A4B2-472D-A760-0D08684C166A} C:\WINDOWS\Installer\a696a.msi 1.96.154.0 Microsoft Intune Management ...
{D5D19E2F-7189-42FE-8103-92CD1FA457C2} C:\WINDOWS\Installer\133631.msi 14.36.32532 Microsoft Visual C++ 2022 X6...

If we closely see i did notice difference between product code in Privilege Management for Windows. I wonder if it has something to do with agent getting update via online and making changes in App GUID.