Throw "Function failed, setting exit code [$returnCode

I am deploying SparkLabs Viscosity version 1.10.2 either using exe or msi installer as an update on an older existing Viscosity installed on the endpoint, after being prompted to Close Programs, and about to execute the install I get this error message

Throw "Function failed, setting exit code [$returnCode

Please see the contents of Deploy-Application.ps1

[CmdletBinding()]
Param (
	[Parameter(Mandatory=$false)]
	[ValidateSet('Install','Uninstall','Repair')]
	[string]$DeploymentType = 'Install',
	[Parameter(Mandatory=$false)]
	[ValidateSet('Interactive','Silent','NonInteractive')]
	[string]$DeployMode = 'Interactive',
	[Parameter(Mandatory=$false)]
	[switch]$AllowRebootPassThru = $false,
	[Parameter(Mandatory=$false)]
	[switch]$TerminalServerMode = $false,
	[Parameter(Mandatory=$false)]
	[switch]$DisableLogging = $false
)

Try {
	## Set the script execution policy for this process
	Try { Set-ExecutionPolicy -ExecutionPolicy 'ByPass' -Scope 'Process' -Force -ErrorAction 'Stop' } Catch {}

	##*===============================================
	##* VARIABLE DECLARATION
	##*===============================================
	## Variables: Application
	[string]$appVendor = 'SparkLabs'
	[string]$appName = 'Viscosity'
	[string]$appVersion = '1.10.2.1745'
	[string]$appArch = ''
	[string]$appLang = 'EN'
	[string]$appRevision = '01'
	[string]$appScriptVersion = '1.0.0'
	[string]$appScriptDate = '05/15/2022'
	[string]$appScriptAuthor = ''
	##*===============================================
	## Variables: Install Titles (Only set here to override defaults set by the toolkit)
	[string]$installName = ''
	[string]$installTitle = ''

	##* Do not modify section below
	#region DoNotModify

	## Variables: Exit Code
	[int32]$mainExitCode = 0

	## Variables: Script
	[string]$deployAppScriptFriendlyName = 'Deploy Application'
	[version]$deployAppScriptVersion = [version]'3.8.4'
	[string]$deployAppScriptDate = '26/01/2021'
	[hashtable]$deployAppScriptParameters = $psBoundParameters

	## Variables: Environment
	If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
	[string]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent

	## Dot source the required App Deploy Toolkit Functions
	Try {
		[string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
		If (-not (Test-Path -LiteralPath $moduleAppDeployToolkitMain -PathType 'Leaf')) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
		If ($DisableLogging) { . $moduleAppDeployToolkitMain -DisableLogging } Else { . $moduleAppDeployToolkitMain }
	}
	Catch {
		If ($mainExitCode -eq 0){ [int32]$mainExitCode = 60008 }
		Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
		## Exit the script, returning the exit code to SCCM
		If (Test-Path -LiteralPath 'variable:HostInvocation') { $script:ExitCode = $mainExitCode; Exit } Else { Exit $mainExitCode }
	}

	#endregion
	##* Do not modify section above
	##*===============================================
	##* END VARIABLE DECLARATION
	##*===============================================

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

		## Show Welcome Message, close viscosity, viscosityservice if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
		Show-InstallationWelcome -CloseApps 'viscosity,viscosityservice' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt

		## Show Progress Message (with the default message)
		Show-InstallationProgress

		## Show Progress Message (with the default message)
        Show-InstallationProgress -StatusMessage "Installing Viscosity version 1.10.2.  Please Wait...."

        ## <Perform Pre-Installation tasks here>
        Start-Sleep -Seconds '20' #line used for testing
		##*===============================================
		##* INSTALLATION
		##*===============================================
		[string]$installPhase = 'Installation'

		## <Perform Installation tasks here>
        
        #install viscosity using exe installer
        Execute-Process -Path "$dirFiles\viscosity-1.10.2.1745-2022-Profiles.exe" -Parameters "/silent /install /norestart"

		##*===============================================
		##* POST-INSTALLATION
		##*===============================================
		[string]$installPhase = 'Post-Installation'

		## <Perform Post-Installation tasks here>

		## Display a message at the end of the install
		If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'Viscosity version 1.10.2.1745 installation is now completed. Click on OK to close this dialog box and re-open Viscosity app' -ButtonRightText 'OK' -Icon Information -NoWait }
	}
	ElseIf ($deploymentType -ieq 'Uninstall')
	{
		##*===============================================
		##* PRE-UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Pre-Uninstallation'

		## Show Welcome Message, close Viscosity with a 60 second countdown before automatically closing
		#Show-InstallationWelcome -CloseApps 'Viscosity,viscosityservice' -CloseAppsCountdown 60

		## Show Progress Message (with the default message)
		#Show-InstallationProgress

		## <Perform Pre-Uninstallation tasks here>


		##*===============================================
		##* UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Uninstallation'

		## Handle Zero-Config MSI Uninstallations
		#If ($useDefaultMsi) {
		#	[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
		#	Execute-MSI @ExecuteDefaultMSISplat
		#}
		# <Perform Uninstallation tasks here>
        
        #Check if Viscosity is installed
        $viscosity = 'C:\Program Files\Viscosity\ViscosityCC.exe'
        If (test-path -Path $viscosity) {

        #Ends Viscosity and Viscosity Service
        & taskkill /im Viscosity.exe /f
        & taskkill /im ViscosityService.exe /f

        #Uninstall Viscosity
        Execute-Process -Path "C:\Program Files\Viscosity\unins000.exe" -Parameters "/VERYSILENT"
        }
		##*===============================================
		##* POST-UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Post-Uninstallation'

		## <Perform Post-Uninstallation tasks here>
        ## Display a message at the end of the Uinstallation
		#If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'Viscosity version 1.10.2.1745 Uninstallation is now completed. Click on OK to close this dialog box' -ButtonRightText 'OK' -Icon Information -NoWait }

	}
	ElseIf ($deploymentType -ieq 'Repair')
	{
		##*===============================================
		##* PRE-REPAIR
		##*===============================================
		[string]$installPhase = 'Pre-Repair'

		## Show Progress Message (with the default message)
		Show-InstallationProgress

		## <Perform Pre-Repair tasks here>

		##*===============================================
		##* REPAIR
		##*===============================================
		[string]$installPhase = 'Repair'

		## Handle Zero-Config MSI Repairs
		#If ($useDefaultMsi) {
		#	[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Repair'; Path = $defaultMsiFile; }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
		#	Execute-MSI @ExecuteDefaultMSISplat
		#}
		# <Perform Repair tasks here>
        Execute-Process -Path "$dirFiles\viscosity-1.10.2.1745-2022-Profiles.exe" -Parameters "/silent /install /norestart"
		##*===============================================
		##* POST-REPAIR
		##*===============================================
		[string]$installPhase = 'Post-Repair'

		## <Perform Post-Repair tasks here>


    }
	##*===============================================
	##* END SCRIPT BODY
	##*===============================================

	## Call the Exit-Script function to perform final cleanup operations
	Exit-Script -ExitCode $mainExitCode
}
Catch {
	[int32]$mainExitCode = 60001
	[string]$mainErrorMessage = "$(Resolve-Error)"
	Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
	Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
	Exit-Script -ExitCode $mainExitCode
}

Screen Shot 2022-05-17 at 6.32.13 PM

If you read your PSADT log file, it will tell you WHICH function failed.

If you don’t have the log file for some reason, open AppDeployToolkitMain.PS1 as shown in the popup you posted and go to line 3315 to determine WHICH function failed.

Thanks, where does PSADT log file usually reside?

Same problem and I looked but maybe i am missing something as well?

[05-18-2022 15:21:46.746] [Installation] [Execute-Process] :: Function failed, setting exit code to [60002].
Error Record:
-------------At C:\temp1\MicroS\AppDeployToolkit\AppDeployToolkitMain.ps1:3168 char:5

  •             $null = $process.Start()
    
  •             ~~~~~~~~~~~~~~~~~~~~~~~~
    

Error Inner Exception(s):

I looked at that line and here is the $null = $process.Start()

are you also trying to update an existing version of an app using PSADT and the new version installer of the app? looks like you are also using exe installer? Issue happens either I use an msi or exe installer and its corresponding command to install exe or msi.

All i am trying to accomplist is run the .exe file.

Execute-Process .\temp1\MicroS\WindowsWorkstation.exe and this is my errors

[05-18-2022 16:15:42.118] [Installation] [Execute-Process] :: Function failed, setting exit code to [60002].
Error Record:
-------------At C:\temp1\MicroS\AppDeployToolkit\AppDeployToolkitMain.ps1:3074 char:35

  • … ifiedPath = Get-Command -Name $Path -CommandType ‘Application’ -Total …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

Function failed, setting exit code to [60002].
Error Record:
-------------At C:\temp1\MicroS\AppDeployToolkit\AppDeployToolkitMain.ps1:918 char:5

  • … [IO.FileInfo]$LogFile = Get-ChildItem -LiteralPath $LogFi …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

Error Inner Exception(s):

At C:\temp1\MicroS\AppDeployToolkit\AppDeployToolkitMain.ps1:3315 char:6

  • … Throw "Function failed, setting exit code to [$returnCode …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: (Function failed…---------------:String) [], RuntimeExcepti
      on
    • FullyQualifiedErrorId : Function failed, setting exit code to [60002].
      Error Record:
      -------------At C:\temp1\MicroS\AppDeployToolkit\AppDeployToolkitMain.ps1:918 char:5
  • … [IO.FileInfo]$LogFile = Get-ChildItem -LiteralPath $LogFi …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

Error Inner Exception(s):

@fqasim
Please create your own post. you have a different issue.
Please include the key command lines of your Deploy-Application.ps1 script.
Please use the the </> tool to format your code and log files.

I found the root cause of my issue, our Anti-Malware was identifying the exe installer as a malware, hence it quarantines it so when it is time to run this command Execute-Process -Path “$dirFiles\viscosity-1.10.2.1745-2022-Profiles.exe” -Parameters “/silent /install /norestart” the installer in the files directory is gone

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.