[PSADT 4.0.6] Custom Exitcode

Hello,

i will use a custom exitcode 69107 but when i start the script with Invoke-AppDeployToolkit.exe the Package will always display a MSGBOX with a An error occurred while running Invoke-AppDeployToolkit.ps1. Exit Code: 69107 at the end of the installation.
If i run the script via powershell.exe and the ps1 directly the MSGBOX will not be displayed.
I don’t understand why, and how can i work around. I Use the Invoke-ServiceUI.PS1.

How can achieve that when i exit a script with a custom exit code but not classified as an error? But instead, for example, as a warning.

Thank You
Greetings
Torte

Hello @Torte,
3 important questions that will help us and you:

  • Are you writing any logs?
  • Where are your logs written to?
  • Have you reviewed the logs?

Hello @Adrian_Scott

thank you.
Yes i write logs. The logs are written to the default folder.

[Initialization] :: *******************************************************************************	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [TESTORG_123_1_x64_EN_01] install started.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [TESTORG_123_1_x64_EN_01] script version is [1.0.0].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [TESTORG_123_1_x64_EN_01] script author is [Torsten].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [Invoke-AppDeployToolkit.ps1] script version is [4.0.6].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: The following parameters were passed to [Invoke-AppDeployToolkit.ps1]: [-DeployMode:'Interactive'].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] module version is [4.0.6].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] module imported in [5,8276874] seconds.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] module initialized in [2,851142] seconds.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] module path is ['D:\RZFSDT\PSAppDeployToolkit_Template_v4.0.6\PSAppDeployToolkit'].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] config path is ['D:\RZFSDT\PSAppDeployToolkit_Template_v4.0.6\Config'].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] string path is ['D:\RZFSDT\PSAppDeployToolkit_Template_v4.0.6\Strings'].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: [PSAppDeployToolkit] session mode is [Native].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Computer Name is [C18024].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Current User is [DOM\User1a].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: OS Version is [Microsoft Windows 10 Enterprise AMD64 10.0.19041.5678].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: OS Type is [Workstation].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Hardware Platform is [Virtual:Hyper-V].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Current Culture is [de-DE], language is [DE] and UI language is [DE].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: PowerShell Host is [ConsoleHost] with version [5.1.19041.5678].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: PowerShell Version is [5.1.19041.5678 AMD64].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: PowerShell CLR (.NET) version is [4.0.30319.42000].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: *******************************************************************************	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Display session information for all logged on users:
 
 
NTAccount           : DOM\User1
SID                 : S-1-5-21-3090795412-787856844-3540091451-399193
UserName            : User1
DomainName          : DOM
SessionId           : 2
SessionName         : RDP-TCP#2
ConnectState        : WTSActive
IsCurrentSession    : True
IsConsoleSession    : False
IsActiveUserSession : True
IsUserSession       : True
IsRdpSession        : True
IsLocalAdmin        : False
LogonTime           : 21.05.2025 06:37:09
IdleTime            : 00:00:08.7381005
DisconnectTime      :
ClientName          : C18024
ClientProtocolType  : RDP
ClientDirectory     : C:\Windows\system32\mstscax.dll
ClientBuildNumber   : 22621
	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: The following users are logged on to the system: [DOM\User1].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Current process is running with user account [DOM\User1a] under logged on user session for [DOM\User1].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Device has completed the OOBE and toolkit is not running with an active ESP in progress.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: There is no console user logged on (user with control of physical monitor, keyboard, and mouse).	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: The active logged on user is [DOM\User1].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: The current execution context has a primary UI language of [DE].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: The following UI messages were imported from the config file: [de-DE].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Unable to find COM object [Microsoft.SMS.TSEnvironment]. Therefore, script is not currently running from a SCCM Task Sequence.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Session 0 not detected.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Installation is running in [Interactive] mode.	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Deployment type is [Install].	Open-ADTSession	21.05.2025 07:55:59	12992 (0x32C0)
[Initialization] :: Module [PSAppDeployToolkit.Extensions] imported successfully.	PSAppDeployToolkit.Extensions.psm1	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Evaluating disk space requirements.	Show-ADTInstallationWelcome	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Retrieving free disk space for drive [C:\].	Get-ADTFreeDiskSpace	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Free disk space for drive [C:\]: [3917 MB].	Get-ADTFreeDiskSpace	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Successfully passed minimum disk space requirement check.	Show-ADTInstallationWelcome	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: The user has [3] deferrals remaining.	Show-ADTInstallationWelcome	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Checking for running applications: [iexplore]	Get-ADTRunningProcesses	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: Specified applications are not running.	Get-ADTRunningProcesses	21.05.2025 07:56:00	12992 (0x32C0)
[Pre-Install] :: The user selected to force the application(s) to close...	Show-ADTInstallationWelcome	21.05.2025 07:56:03	12992 (0x32C0)
[Pre-Install] :: Checking for running applications: [iexplore]	Get-ADTRunningProcesses	21.05.2025 07:56:03	12992 (0x32C0)
[Pre-Install] :: Specified applications are not running.	Get-ADTRunningProcesses	21.05.2025 07:56:03	12992 (0x32C0)
[Pre-Install] :: Creating the progress dialog in a separate thread with message: [Installation wird durchgeführt. Bitte warten...].	Show-ADTInstallationProgress	21.05.2025 07:56:03	12992 (0x32C0)
[Finalization] :: Closing the installation progress dialog.	Close-ADTInstallationProgressFluent	21.05.2025 07:56:03	12992 (0x32C0)
[Finalization] :: [TESTORG_123_1_x64_EN_01] install completed with exit code [69107].	Close-ADTSession	21.05.2025 07:56:03	12992 (0x32C0)
[Finalization] :: *******************************************************************************	Close-ADTSession	21.05.2025 07:56:03	12992 (0x32C0)


Looking at these lines in your log, it appears that the messaging that the user will see appears correctly during the Pre-Install section, but the script then exits before the actual application installer is executed.

Can you supply a snippet of your script showing what you are running in the Pre-Install, Install and Post-Install sections? - It feels like there is something not configured correctly (maybe something as simple as a missing quote or bracket :man_shrugging:)

hi @Adrian_Scott

thank you again :slight_smile:

function Install-ADTDeployment
{
    ##================================================
    ## MARK: Pre-Install
    ##================================================
    $adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"

    ## 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-ADTInstallationWelcome -CloseProcesses iexplore -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt

    ## Show Progress Message (with the default message).
    Show-ADTInstallationProgress

    ## <Perform Pre-Installation tasks here>


    ##================================================
    ## MARK: Install
    ##================================================
    $adtSession.InstallPhase = $adtSession.DeploymentType

    ## Handle Zero-Config MSI installations.
    if ($adtSession.UseDefaultMsi)
    {
        $ExecuteDefaultMSISplat = @{ Action = $adtSession.DeploymentType; FilePath = $adtSession.DefaultMsiFile }
        if ($adtSession.DefaultMstFile)
        {
            $ExecuteDefaultMSISplat.Add('Transform', $adtSession.DefaultMstFile)
        }
        Start-ADTMsiProcess @ExecuteDefaultMSISplat
        if ($adtSession.DefaultMspFiles)
        {
            $adtSession.DefaultMspFiles | Start-ADTMsiProcess -Action Patch
        }
    }

    ## <Perform Installation tasks here>
	Close-ADTSession -exitcode 69107

    ##================================================
    ## MARK: Post-Install
    ##================================================
    $adtSession.InstallPhase = "Post-$($adtSession.DeploymentType)"

    ## <Perform Post-Installation tasks here>


    ## Display a message at the end of the install.
    if (!$adtSession.UseDefaultMsi)
    {
        Show-ADTInstallationPrompt -Message 'You can customize text to appear at the end of an install or remove it completely for unattended installations.' -ButtonRightText 'OK' -Icon Information -NoWait
    }
}

It’s only a testscript with the exitcode. Nothing will done with this script ;-). Based on fresh downloaded 4.0.6 Template. We use our scripts with the invoke-servicesui.ps1 and there the scripts will be started with the invoke-applikation.exe. Only than you see the msgbox i attached.

The second question: How can I declare my custom exit code so that it is not classified as an error?

greetings
torsten