Stop script if file version, file or registry entry exists?

I have an install script that works great at installing a new version of an app we use that req’s outlook and itself be closed when installing/updated it. The issue that I’m facing now is on machines that were manually updated to a newer version that the script is pushing, keep trying to run despite there being a new version.

Sccm thinks the install failed so it tries again…and again…and again. The pc is part of a regional collection so I can’t just remove the deployment or other machines that actually need it won’t get it installed.

I need to either place a reg entry or a file, or quit the script based on file version.

Any ideas? I’ve tried getting the file version, but can’t seem to get it into a variable to use in an if fileversion=x.xx then exit, else continue.

I’m open to any ideas, not just an if/then/else statement.

Thanks in advance.

ok, deleted the earlier post I made as it didn’t work and had some extra garbage in it.

Re-wrote this one, and it’s nice and simple and seems to work fine:

 ## Check file version and proceed, Close Outlook and Xink, and persist the prompt
        $XinkVersion = (get-item 'C:\Program Files (x86)\Xink\Xink Client AD\emsclient.exe').VersionInfo.FileVersion
        
        if($XinkVersion -gt 3.2.8){
            
            Exit 0
        }
        else {


		## Show Welcome Message, close Xink if required, and persist the prompt
		Show-InstallationWelcome -CloseApps 'outlook,emsclient' -PersistPrompt
		}
		## Show Progress Message (with the default message)
		Show-InstallationProgress

Couldn’t you have just set a Detection Method for the systems that don’t need the script run on them?

Perhaps a rule to confirm the new app is installed via sccm, and/or a rule to confirm its already been updated.

If those 2 rules would be the same, maybe write a dummy reg key during the psappdeploy and use that

I have it being pushed out as a package so don’t think I can enter a detection method. But I definitely like the idea, I’ll have to do some more research on it, haven’t done that yet and would be very helpful going forward.

I use this code to determine the installed version and depending on the outcome, I perform an clean install or an update. In this case its About Visual Studio:

[version]$VisualStudio = (Get-InstalledApplication -Name “Visual Studio Professional 2017”).DisplayVersion

If ($null -eq $VisualStudio ) {
Write-Log -Message "Appname Not installed, start installation" -Source {CmdletName}
#HERE YOUR INSTALLATION COMMAND
}
Else{
Write-Log -Message "Installation found. Version VisualStudio" -Source {CmdletName}
If ($VisualStudio -lt ‘15.9.28307.1033’){
Write-Log -Message "Version VisualStudio is lower then 15.9.28307.770, starting update." - Source {CmdletName}
#HERE YOUR UPDATE COMMAND
}
}

You can also use this to apply updates (if they are not MSI or MSP Files) or a clean install.