Exit script successful if Application exists?

Hi All,

I am just starting to use this amazing tool and getting more in depth into powershell. I am trying to deploy an application with the script, which works perfectly.

What I am trying to accomplish is try add an IF statement to beginning of the script, to check if the particular application and version are installed. If installed, I would like the script to exit as success. If not installed, to proceed as normal.

Thank you in advance!

I am trying something along the lines of what is shown below but not getting much luck. Any help is appreciated.

If ($deploymentType -ine ‘Uninstall’) {
##===============================================
##
PRE-INSTALLATION
##*===============================================
[string]$installPhase = ‘Pre-Installation’

	$regpath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FDC50EB2-30B3-43C7-984A-B631FED09570}"

	$testpath = test-path $regpath

if ($testpath -eq $true){
	Exit-Script -ExitCode $mainExitCode
	}
	else{

	## Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
	Show-InstallationWelcome -CloseApps 'iexplorer' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt -CustomText
	
	## Show Progress Message (with the default message)
	Show-InstallationProgress -StatusMessage "Installation in Progress. Please wait..." }

Hello,

Just update $regpath same as below :

$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FDC50EB2-30B3-43C7-984A-B631FED09570}"

Test-Path doesn’t recognize HKLM without colon (:).

Hi! Thanks for the reply, I have tried to update it and it seems to exit the script regardless of the outcome. I confirmed in Regedit that the path does not exist and it still exits the script.

Any idea why this could be happening?\

EDIT: I figured it out, forgot to close it out with } :slight_smile: – the simplest typos make the biggest difference.

I appreciate your help!

Always welcome. By your Edit section I understood that its working now. Right ?

It indeed is. Thank you!

1 Like