I would like to use the inline powershell custom action to remove applications that are not part of the installer. I have an exe that installs using feature based prerequisites and after the FinishExecution stage I run an inline script to uninstall some older applications using this:
# Block for declaring the script parameters.
Param($desktopPrereq, $ver, $uninst, $_)
#Uninstall My_Application
$desktopPrereq = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {$_.DisplayName -match "My_Application" } |
Select-Object -Property DisplayName, UninstallString
ForEach ($ver in $desktopPrereq) {
If ($ver.UninstallString) {
$uninst = $ver.UninstallString
Start-Process cmd -ArgumentList "/c $uninst /quiet /norestart" -NoNewWindow -Wait
}
}
or this
# Block for declaring the script parameters.
Param($uninstall_base_version_1, $uninstall_base_version_2, $uninstall_base_version_3, $uninstall_base_version_4, $old_desktop_prereq, $old_scanner_prereq)
$uninstall_base_version_1="6.1"
$uninstall_base_version_2="6.2"
$uninstall_base_version_3="6.3"
$uninstall_base_version_4="6.4"
# Uninstall My_Application
$old_desktop_prereq=Get-WmiObject -Class Win32_Product | sort-object Name | where { $_.Name -match "My_Application" -and ($_.Version -like "$($uninstall_base_version_1)*" -or $_.Version -like "$($uninstall_base_version_2)*" -or $_.Version -like "$($uninstall_base_version_3)*" -or $_.Version -like "$($uninstall_base_version_4)*")}
if ($old_desktop_prereq) {
$old_desktop_prereq.Uninstall()
}
# Uninstall My_Application
$old_scanner_prereq=Get-WmiObject -Class Win32_Product | sort-object Name | where { $_.Name -match "My_Application" -and ($_.Version -like "$($uninstall_base_version_1)*" -or $_.Version -like "$($uninstall_base_version_2)*" -or $_.Version -like "$($uninstall_base_version_3)*" -or $_.Version -like "$($uninstall_base_version_4)*")}
if ($old_scanner_prereq) {
$old_scanner_prereq.Uninstall()
}
When I run it from PS, it works, but when I run it as an inline script custom action, it doesn't work. I have tried it at different execution times and execution stages with no success.
FOLLOW US
Get the latest news in Application Packaging