Task Scheduler can't send email any more: get an alert when a task fails
You want an email when a Windows scheduled task fails, and Task Scheduler's own Send an e-mail action is greyed out or gives an error. The action is gone, the usual event-log workaround has gaps, and there is a simpler way to get an email, or a Slack or Teams message, when a task fails or doesn't run.
Why Task Scheduler can't email you any more
Microsoft deprecated two Task Scheduler actions in Windows 8: Send an e-mail and Display a message. Its page "What's New in Task Scheduler" lists them under deprecated features and suggests running a script with Send-MailMessage instead. But Send-MailMessage is itself marked obsolete now: Microsoft says it can't guarantee a secure connection to the mail server and shouldn't be used. So the official replacement for the removed action is also on its way out.
The workaround most forum answers give is a second task, triggered On an event from the log Microsoft-Windows-TaskScheduler/Operational, that sends the mail. It works, with three catches:
- The operational log is off by default; you turn it on with Enable All Tasks History.
- Event 201 (action completed) fires on success as well as failure, so the trigger needs a custom XML filter on the result code; event 101 covers a task that failed to start. Microsoft's own list of these event IDs dates from the Windows Server 2008 era.
- A run that never happened writes no event at all. If the PC was off or the task's account couldn't log on, nothing triggers the email. Forum threads asking for "an alert when the task did NOT run" tend to stay unanswered for that reason.
You also still need an SMTP server that accepts mail from that machine, which many company networks don't allow.
Let the task report to TaskBeacon instead
Instead of watching the event log, let the task report its own result over HTTPS. The PowerShell script below runs your program, waits for it, and sends its exit code to TaskBeacon; on a failure it adds the last 20 lines of output. It then exits with the same code, so Task Scheduler's Last Run Result stays honest.
# Save as C:\jobs\taskbeacon-run.ps1
# Task Scheduler > Action: Start a program
# Program: powershell.exe
# Arguments: -NoProfile -ExecutionPolicy Bypass -File C:\jobs\taskbeacon-run.ps1 "C:\path\to\program.exe" "arg1" "arg2"
# Runs the program, then reports success or failure from its exit code.
# A .ps1 script as the program is run with powershell.exe -NoProfile -ExecutionPolicy Bypass -File script.ps1
# (an execution policy set by Group Policy still wins over Bypass).
$tb = "https://taskbeacon.io/ping/your-job-id"
$program, $programArgs = $args
# a .ps1 file is not a program Windows can start on its own ("not a valid Win32 application")
if ($program -match '\.ps1$') {
$programArgs = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $program) + @($programArgs | Where-Object { $null -ne $_ })
$program = 'powershell.exe'
}
function Send-TaskBeacon($path, $text) {
$send = @{ UseBasicParsing = $true; TimeoutSec = 10; Uri = ($tb + $path) }
if ($text) { $send.Method = 'Post'; $send.ContentType = 'text/plain; charset=utf-8'; $send.Body = [Text.Encoding]::UTF8.GetBytes($text) }
try { Invoke-WebRequest @send | Out-Null }
catch { Write-Host "TaskBeacon ping failed: $_" }
}
Send-TaskBeacon "/start"
# keep arguments that contain spaces together
$argLine = ($programArgs | ForEach-Object { if ($_ -eq '' -or $_ -match '[\s"]') { '"' + ($_ -replace '"', '\"') + '"' } else { $_ } }) -join ' '
# Windows PowerShell 5.1 refuses an empty -ArgumentList: pass it only when there are arguments
$run = @{ FilePath = $program; Wait = $true; PassThru = $true; NoNewWindow = $true; ErrorAction = 'Stop' }
if ($argLine) { $run.ArgumentList = $argLine }
# the program's output goes to temporary files: shown below, and its last 20 lines go with a failure
$out = [IO.Path]::GetTempFileName(); $err = [IO.Path]::GetTempFileName()
$run.RedirectStandardOutput = $out; $run.RedirectStandardError = $err
$code = 1
$note = ''
try {
$p = Start-Process @run
if ($null -ne $p.ExitCode) { $code = $p.ExitCode }
} catch { $note = "Could not start ${program}: $_"; Write-Host $note }
Get-Content -LiteralPath $out, $err -ErrorAction SilentlyContinue
$tail = ''
if ($code -ne 0) {
$lines = @(Get-Content -LiteralPath $out, $err -Tail 20 -ErrorAction SilentlyContinue) + @($note)
$tail = ($lines | Where-Object { $_ } | ForEach-Object { if ($_.Length -gt 300) { $_.Substring(0, 300) } else { $_ } }) -join "`n"
}
# the exit code goes at the end of the address: /0 = OK, any other number = failed
Send-TaskBeacon "/$code" $tail
Remove-Item -LiteralPath $out, $err -ErrorAction SilentlyContinue
exit $code # not 0 when it failed, so Task Scheduler shows the failure tooIn the app, the Code tab of your job gives you this code with the job's own address instead of your-job-id, and you can untick the parts you don't need.
In the task's action set Program to powershell.exe and Arguments as in the comment at the top, with your program and its arguments at the end. Nothing else is needed on the machine: no SMTP server, no mail profile, no second task.
What you get
- An email when the task fails, with the exit code and the last lines of output. The same alert can go to Slack, Microsoft Teams, Discord, Google Chat, ntfy or a webhook, and to colleagues' addresses (see Alerts).
- An email when the task doesn't run: set the job's schedule like the task's trigger (daily at 06:00, weekdays, every 2 hours …), and when no ping comes by the planned time plus grace, the job turns Missed. This is the case the event-log trigger can't see.
- An email when it runs much longer than usual (Late), and one when it is back to OK.
If the program returns 0 even when it fails, a wrapper can't tell; report from inside the script instead, for example with the Python or R code. Why that happens is on Task Scheduler shows 0x0 but the script failed.
Without TaskBeacon
Enable the task history, create a task triggered on event 201 of Microsoft-Windows-TaskScheduler/Operational with an XML filter for a non-zero ResultCode and the task's name, and let it run a PowerShell script that sends mail through your SMTP server (with a mail library, since Send-MailMessage is obsolete). Add a second trigger on event 101 for tasks that fail to start. That covers failures on that one machine. For runs that never happen you need something outside the machine that expects a signal, which is what a heartbeat check is.
Connected Claude or ChatGPT to TaskBeacon? Ask it "what failed last night, and why?" and it answers from your jobs. How that works.
Related
In the Docs: PowerShell (Task Scheduler) · Alerts · Schedules.
- Task Scheduler Last Run Result 0x0, but the script failedLast Run Result 0x0 only means the program it started returned 0.
- Find out when a scheduled job didn't run at allA run that never happened leaves no error to alert on.
- PowerShell script errors and the exit code in Task SchedulerNon-terminating errors leave exit code 0; -Command squashes codes to 0 or 1.
TaskBeacon is free to start, with every feature open for now and no credit card. Create a job, paste the code, and the first ping shows up on the job page.
Start free View live demoSources
- Microsoft Learn: What's New in Task Scheduler (sendEmail and showMessage deprecated in Windows 8) (2018-05-31, updated 2025-03-11; still the current page)
- Microsoft Learn: Send-MailMessage (marked obsolete) (2024-06-18, updated 2026-06-16)
- Microsoft Learn (previous versions): Task Scheduler event IDs, e.g. 101 task start failed (about 2009, old: no current page lists these IDs)
- Microsoft Q&A: How to create email alerts for task scheduler job fails (send email option is deprecated) (2023-10-26, old: a sign of demand)
- Microsoft Q&A: How to schedule a script and set up email notification via Task Scheduler (2024-04-27)
Page checked against its sources on 2026-11-19. Menus and limits of other products change; if something here no longer matches, write to support@taskbeacon.io.