I am automating some report generation with Powershell. It is an unpleasant business, collaging together PDFs with Excel interop and third-party DLLs. Due to all the sketchy things I'm trying to marshall together, sometimes my powershell process dies completely. To mitigate this, I'm running it in a supervisor script something like this:
while($moreToDo) {
try {
powershell -NonInteractive -NoProfile ./generate-report.ps1
}
catch {
# clean up
Write-Host "Failed. Trying again..."
}
}
However, when the powershell
process dies, I get a 'windows powershell has stopped working' dialog:
This dialog blocks the supervisor script from continuing, which makes my supervisor script pretty pointless.
Is there a way to invoke powershell so that if it fails catastrophically , it doesn't pop up this message and instead just dies?