PowerShell Error Handling for Reliable Microsoft 365 ScriptsPowerShell Error Handling for Reliable Microsoft 365 Scripts
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
PowerShell tip: make errors actually stop your script.
Many cmdlets throw "non-terminating" errors. Your try/catch never fires, the loop keeps going, and you find out later that a handful of mailboxes never got updated.
What I do in bulk Microsoft 365 scripts:
- Add -ErrorAction Stop to the cmdlet inside try, so a failure jumps to catch.
- In catch, log the item and $_.Exception.Message to a failures list instead of letting the script die.
- At the end, export the failures to CSV and print how many succeeded and how many failed.
- Fix the cause, then rerun only the failed CSV.
You get a clean retry list instead of guessing what got skipped.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started