Testing for a condition and handling the exit code

What is the proper way of exiting PSADT if a condition fails? Is this correct?

if ( Test-Path "\\some\remote\share" ) {
     Execute-Process "the_installer.exe"
} else {
     Write-Host "Can't reach the shared folder!"
    exit 60012
}

I realize I could just let Execute-Process fail but I would like to know WHY it failed.

The scenario that’s driving this is an installation package of 20GB which is far beyond what Intune allows (8GB). So I am forced to put the installation folder on an internal shared drive but the people running this would be on laptops and may forget to run their VPN client prior to attempting the install despite a big red warning in the Company Portal.

The WHY should show up in the log file.

But if you want to “handle” the exitcode, as per the PDF:
EXAMPLE 3

[psobject]$ExecuteMSIResult = Execute-MSI -Action 'Install' -Path
'Adobe_FlashPlayer_11.2.202.233_x64_EN.msi' -PassThru

Installs an MSI and stores the result of the execution into a variable by using the -PassThru option

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