Trying to pull uninstall string for EXE uninstall

Sorry if this is a duplicate, I posted a bit ago, I edited the post and then it appeared to have disapeared. I wanted to add something else to my post and cant find it now :slight_smile:

I am really struggling with uninstalling apps that are EXE based uninstalls. The only method I have found that works is to put the actual path to the uninstall exe in the Path parameter.

Here is my current uninstall section
<pre class=“brush: powershell; gutter: true; first-line: 1; highlight: []; html-script: false”>
Function Uninstall-Application
{
<#
.SYNOPSIS
Perform all tasks necessary to remove the target application.
.DESCRIPTION
Perform all tasks necessary to remove the target application. The machine should
be left in a condition that would allow the wrapper to immediately attempt to
reinstall the application again.
.PARAMETER ContinueOnError
Default is $true; if $false exceptions and errors will be returned to caller.
.EXAMPLE
Uninstall-Application
.NOTES

    .LINK
    #&gt;
	[CmdletBinding()]
	Param (
		[Parameter(Mandatory = $false)]
		[ValidateNotNullorEmpty()]
		[boolean]$ContinueOnError = $true
	)
	
	Begin
	{
		## Get the name of this function and write header
		[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
		Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
	}
	Process
	{
		Try
		{
			Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Searching for existing installs.<code>n</code>nPlease wait...&quot;
			Get-InstalledApplication -Name &#039;SoapUI&#039; -RegEx | ForEach-Object {
				# Early beta releases were tagged as coming from IBM; display name has been evolving so need to double verify
				If ($_.Publisher -match &#039;SmartBear&#039;)
				{
					Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName).<code>n</code>nPlease wait...&quot;
					If ($_.UninstallString -match &#039;msiexec&#039;)
					{
						Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
						Remove-MSIApplications -Name $_.DisplayNameExact -Parameters &quot;REBOOT=ReallySuppress /QN&quot;
					}
					ElseIf ($_.UninstallString -match &#039;^.+\.exe&#039;)
					{
						write-log -message &quot;uninstall string = $_.UninstallString&quot;
						Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
						Execute-Process -path &quot;&lt;path to the EXE&gt;&quot; -Parameters &quot;-q&quot;
					}
				}
			}
		}
		Catch
		{
			Write-Log -Message &quot;Failed to uninstall application. `n$(Resolve-Error)&quot; -Severity 3 -Source ${CmdletName}
			If (-not $ContinueOnError)
			{
				Throw &quot;Failed to uninstall application: $($_.Exception.Message)&quot;
				Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
				
			}
		}
		Finally
		{
			## If there is any resource cleanup that must be done regardless if an exception occurs put it here
		}
	}
	End
		{
			Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
		}
	
}

The Log shows that $_.uninstallstring = <![LOG[[Uninstallation] :: uninstall string = @{InstallDate=; Publisher=SmartBear Software; UninstallString=“C:\Program Files\SmartBear\SoapUI-5.4.0\uninstall.exe”; Is64BitApplication=True; InstallSource=; UninstallSubkey=5517-2803-0637-4585; ProductCode=; DisplayVersionExact=5.4.0; DisplayName=SoapUI 5.4.0 5.4.0; PublisherExact=SmartBear Software; DisplayNameExact=SoapUI 5.4.0 5.4.0; DisplayVersion=5.4.0; InstallLocation=C:\Program Files\SmartBear\SoapUI-5.4.0}.UninstallString]LOG]!><time=“13:09:32.540-300” date=“08-16-2018” component="" context=“GM-Win7-64\Administrator” type=“1” thread=“1724” file=“Deploy-Application.ps1”>

Shouldn’t the $_Uninstallstring just return the uninstall string? not all the properties of the key?
The log then shows an error of
Message : Exception calling “IsPathRooted” with “1” argument(s):
“Illegal characters in path.”
InnerException : System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path,
Boolean checkAdditional)
at System.IO.Path.IsPathRooted(String path)
at CallSite.Target(Closure , CallSite , RuntimeType ,
Object )

I’m guessing this is because of the entire list of properties being returned?

I know enough Powershell to be dangerous, mainly to myself LOL, so any help would be greatly appreciated.

I am trying to uninstall all previous versions of SoapUI, and our company has more than 10 versions installed so I would really rather not have to check for each version and then call the “correct” uninstall exe path for each.

Well I was doing more searching and found this post over on ITNinja
https://www.itninja.com/blog/view/how-to-uninstall-program-by-name-only

In looking at the code supplied it looked very simular to the PSADT uninstall app code.

I added his code (tweaked to match PSADT naming etc) and changed the uninstall section to
<pre class=“brush: powershell; gutter: true; first-line: 1; highlight: []; html-script: false”>
Function Uninstall-Application
{
<#
.SYNOPSIS
Perform all tasks necessary to remove the target application.
.DESCRIPTION
Perform all tasks necessary to remove the target application. The machine should
be left in a condition that would allow the wrapper to immediately attempt to
reinstall the application again.
.PARAMETER ContinueOnError
Default is $true; if $false exceptions and errors will be returned to caller.
.EXAMPLE
Uninstall-Application
.NOTES

    .LINK
    #&gt;
	[CmdletBinding()]
	Param (
		[Parameter(Mandatory = $false)]
		[ValidateNotNullorEmpty()]
		[boolean]$ContinueOnError = $true
	)
	
	Begin
	{
		## Get the name of this function and write header
		[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
		Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
	}
	Process
	{
		Try
		{
			Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Searching for existing installs.<code>n</code>nPlease wait...&quot;
			Get-InstalledApplication -Name &#039;SoapUI&#039; -RegEx | ForEach-Object {
				# Early beta releases were tagged as coming from IBM; display name has been evolving so need to double verify
				If ($_.Publisher -match &#039;SmartBear&#039;)
				{
					Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName).<code>n</code>nPlease wait...&quot;
					If ($_.UninstallString -match &#039;msiexec&#039;)
					{
						Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
						Remove-MSIApplications -Name $_.DisplayNameExact -Parameters &quot;REBOOT=ReallySuppress /QN&quot;
					}
					ElseIf ($_.UninstallString -match &#039;^.+\.exe&#039;)
					{
						$uninstallstring= $_.UninstallString.Replace(&#039;&quot;&#039;, &quot;&quot;)
						write-log -message &quot;uninstall string = $uninstallstring&quot;
						Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
						Execute-Process -path $uninstallstring -Parameters &quot;-q&quot;
					}
				}
			}
		}
		Catch
		{
			Write-Log -Message &quot;Failed to uninstall application. `n$(Resolve-Error)&quot; -Severity 3 -Source ${CmdletName}
			If (-not $ContinueOnError)
			{
				Throw &quot;Failed to uninstall application: $($_.Exception.Message)&quot;
				Show-InstallationProgress -WindowLocation &#039;BottomRight&#039; -StatusMessage &quot;Attempting to uninstall $($_.DisplayName) using the Windows Installer service.<code>n</code>nPlease wait..&quot;
				
			}
		}
		Finally
		{
			## If there is any resource cleanup that must be done regardless if an exception occurs put it here
		}
	}
	End
		{
			Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
		}
	
}
and it worked!!! I have 100% no clue what the ".Replace('"', "")" that was added on the end of $_.UninstallString actually did, but the log shows the correct uninstall string and it uninstalled the app.