- PowerShell 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
The 00:00 run listed the log folder, spent ~20 s scanning the two newest archives, and only then opened nEmail.log by name. NLog rotates on the first write after midnight, so by then the pre-midnight file had been renamed to nEmail.<date>_0000.log and the name pointed at a nearly empty new file. The previous hour's polls were never read and every mailbox was reported STALE at ~60 min until the 01:00 run. - Open every selected file before scanning any; a held handle follows the rename. - Re-list the folder after scanning and read any file whose first timestamp has not been seen (new live file); a renamed archive is recognized and not read twice. - Always include the live nEmail.log and read it last instead of trusting its lazily updated LastWriteTime. - Track the newest log timestamp as a maximum, not the last line read. - Write a NOTE line to monitor-run.log when a rotation is caught mid-run. Version 2026.10.29. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> |
||
| .gitignore | ||
| Monitor-EmailPollers.ps1 | ||
| README.md | ||
IS Email Poller Monitor
PowerShell script that watches the Amtelco Intelligent Series (IS) email
service log (nEmail.log and its rotated archives) and reports whether every
Microsoft Graph receive mailbox is still being polled. It discovers mailboxes
from the log, so new accounts need no script changes, and it emails an HTML
status table through an unauthenticated SMTP relay. Runs hourly from Task
Scheduler. Windows PowerShell 5.1, no modules required.
Statuses
| Status | Meaning |
|---|---|
| OK | Polled within the stale window (default 5 minutes; pollers run every 31 s). |
| STALE | No poll in the stale window. |
| HUNG | A Graph CheckEmailAsync call was started and never returned or errored. The poller is stuck; the IS service needs a full restart, not a config reload. |
| ERRORING | Still polling but the most recent check failed. |
| NEVER POLLED | Seen in the log but has never completed a check. |
Exit code 0 when all mailboxes are OK, 2 when any need attention, 1 if the
script itself failed (the failure is appended to monitor-run.log).
Active / standby servers
The script is installed identically on both IS servers. On every run it checks
the Windows service named by -ServiceName (default Amtelco Intelligent Series):
- Service running: normal run and report.
- Service stopped on the host that was reporting last run: one
[PROBLEM]email saying so, then that host goes quiet. - Service stopped and host already quiet: nothing sent, one
STANDBYline in the run log. - Service starts on the host again: the mailbox list is rebuilt from log lines written after the service started.
Use -NoServiceCheck on a single-server install or when testing against
copied logs on a workstation.
Install
-
Copy
Monitor-EmailPollers.ps1toC:\Scriptson each server. -
Seed the state once from history (takes a few minutes for ~400 MB of logs):
C:\Scripts\Monitor-EmailPollers.ps1 -LogDir 'C:\Program Files\Amtelco\Amtelco Intelligent Series Server\Logs' -Rebuild -
Register the hourly task (elevated prompt). Replace the relay and addresses with your own.
$taskArgs = '-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\Monitor-EmailPollers.ps1" ' + '-LogDir "C:\Program Files\Amtelco\Amtelco Intelligent Series Server\Logs" ' + '-SmtpServer 192.0.2.25 -SmtpPort 25 ' + '-MailTo ops@example.com,noc@example.com -MailFrom ispoller@example.com -Quiet' $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $taskArgs -WorkingDirectory 'C:\Scripts' $start = (Get-Date).Date.AddHours((Get-Date).Hour + 1) $trigger = New-ScheduledTaskTrigger -Once -At $start -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-TimeSpan -Days 3650) $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 15) -StartWhenAvailable -MultipleInstances IgnoreNew $principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest Register-ScheduledTask -TaskName 'IS Email Poller Monitor' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Description 'Hourly check that every IS Graph mailbox is still polling; emails an HTML status report.'
The relay must allow the sending server by IP; no SMTP credentials are used or stored anywhere.
Files written next to the script
PollerState.json: per-mailbox state and the high-water mark of processed log lines. Contains mailbox addresses; ignored by git.monitor-run.log: one line per run, plus full detail of any script failure. Ignored by git. ANOTEline appears when the log rotated while a run was in progress (the midnight rollover lands on the 00:00 run); that run reads the new file too.
Delete PollerState.json (or run with -Rebuild) to forget mailboxes that
were removed from IS.
Parameters
Run Get-Help .\Monitor-EmailPollers.ps1 -Full for the complete list. The
ones used day to day: -LogDir, -SmtpServer, -SmtpPort, -MailTo,
-MailFrom, -StaleMinutes, -OnlyOnProblem, -HtmlOut (write the report
to a file for preview), -Quiet, -Rebuild, -ServiceName,
-NoServiceCheck.