Exit codes

Started by bottomleypotts, August 11, 2024, 05:37:36 PM

Previous topic - Next topic

bottomleypotts

Is it possible to determine the exitcode that a powershell script exits with?

spl

a simple explanation
# Run the script
.\my-script.ps1

# Check the exit code
if ($LASTEXITCODE -eq 0) {
  # Script was successful
  Write-Host "The script ran successfully"
} else {
  # Script failed
  Write-Host "The script failed with exit code $LASTEXITCODE"
}

but there are other considerations for error handling https://thinkpowershell.com/powershell-error-handling-techniques/
Stan - formerly stanl [ex-Pundit]