WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bottomleypotts on August 11, 2024, 05:37:36 PM

Title: Exit codes
Post by: bottomleypotts on August 11, 2024, 05:37:36 PM
Is it possible to determine the exitcode that a powershell script exits with?
Title: Re: Exit codes
Post by: spl on August 12, 2024, 02:59:30 AM
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/