What It Does
The script reads the System event log for the last LookbackDays and counts three kinds of event: Kernel-Power 41, which means the PC restarted without shutting down cleanly; EventLog 6008, which records that the previous shutdown was unexpected; and BugCheck 1001, which is a blue screen.
It alerts when the count is more than MaxEvents. It counts event records, so one blue screen can count more than once. The bugcheck code is shown when the event carries one, and the 50 newest events are listed.
Before You Run It
- Set MaxEvents for event records. One crash can generate multiple records.
- A power cut writes the same events as a crash. Ask about the building before you replace hardware.
- Keep the bugcheck codes from the rows. They are what the next step of the diagnosis needs.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 15 seconds.
- Example answer: "3 crash events in 7 days; latest 2026-11-14 bugcheck 0x0000009f"
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- LookbackDays: How many days of the System log to read. Whole number, 1 to 365. Default 7.
- MaxEvents: Alert when more than this many events are found. Whole number, 0 to 100000. Default 0 (any event alerts).
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.