Execute Code Block on Forced Exit?

Viewed 55

I'm writing a script that runs for a long duration that, among other things, accumulates an array of log entries that are saved to file at regular intervals (just not every time an entry is added). The problem I need to account for is what happens if the script is terminated mid-execution and some log files aren't saved.

Is there a way to tell Powershell to run a code block like Add-Content -Path $LogLocation -Value $NewLogs before it actually exits?

1 Answers
Related