Reputation: 3857
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?
Upvotes: 1
Views: 743
Reputation: 9266
That dialog is put up by the Windows Error Reporting system. It's the OS responding to the powershell.exe process crashing.
It is possible to disable WER or to configure WER to ignore powershell.exe. See https://stackoverflow.com/a/3637710. That's a very dangerous road to travel, however.
A much better idea is to modify your script to not crash PowerShell. If you post a question with code, we may be able to help you figure out what is causing the crash and how to avoid it.
Upvotes: 3