Task Scheduler अब email नहीं भेज सकता: task fail होने पर alert पाएँ
आप चाहते हैं कि Windows scheduled task fail होने पर email आए, और Task Scheduler का अपना Send an e-mail action greyed out है या error देता है। वह action जा चुका है, आम event-log workaround में कमियाँ हैं, और task fail होने या न चलने पर email, या Slack या Teams message पाने का एक आसान तरीका है।
Task Scheduler अब आपको email क्यों नहीं कर सकता
Microsoft ने Windows 8 में Task Scheduler के दो actions deprecate किए: Send an e-mail और Display a message। उसका पेज "What's New in Task Scheduler" इन्हें deprecated features में सूचीबद्ध करता है और इनकी जगह Send-MailMessage वाली script चलाने का सुझाव देता है। लेकिन Send-MailMessage खुद अब obsolete चिह्नित है: Microsoft कहता है कि वह mail server से सुरक्षित connection की गारंटी नहीं दे सकता और इसे इस्तेमाल नहीं करना चाहिए। तो हटाए गए action का आधिकारिक विकल्प भी जाने की राह पर है।
ज़्यादातर forum जवाब जो workaround देते हैं, वह एक दूसरा task है, जो log Microsoft-Windows-TaskScheduler/Operational से On an event पर trigger होता है और mail भेजता है। यह काम करता है, तीन दिक्कतों के साथ:
- Operational log default रूप से बंद है; आप इसे Enable All Tasks History से चालू करते हैं।
- Event 201 (action completed) सफलता पर भी उतना ही fire होता है जितना failure पर, इसलिए trigger को result code पर एक custom XML filter चाहिए; event 101 उस task को कवर करता है जो शुरू होने में fail हुआ। इन event IDs की Microsoft की अपनी सूची Windows Server 2008 के दौर की है।
- जो run हुआ ही नहीं वह कोई event नहीं लिखता। अगर PC बंद था या task का account log on नहीं कर पाया, तो कुछ भी email को trigger नहीं करता। "task के न चलने पर alert" माँगने वाले forum threads इसी वजह से अक्सर बिना जवाब के रह जाते हैं।
आपको फिर भी ऐसा SMTP server चाहिए जो उस machine से mail स्वीकार करे, जिसकी कई company networks अनुमति नहीं देते।
इसकी जगह task को TaskBeacon को रिपोर्ट करने दें
Event log पर नज़र रखने की जगह, task को HTTPS पर अपने नतीजे की खुद रिपोर्ट करने दें। नीचे की PowerShell script आपका program चलाती है, उसका इंतज़ार करती है, और उसका exit code TaskBeacon को भेजती है; failure पर यह output की आख़िरी 20 lines जोड़ती है। फिर यह उसी code के साथ exit करती है, ताकि Task Scheduler का Last Run Result ईमानदार रहे।
# 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 tooApp में, आपके job का Code tab आपको यही code देता है, your-job-id की जगह job के अपने address के साथ, और जिन हिस्सों की ज़रूरत नहीं उनका tick आप हटा सकते हैं।
Task के action में Program को powershell.exe पर सेट करें और Arguments ऊपर के comment के अनुसार, अंत में अपने program और उसके arguments के साथ। Machine पर और कुछ नहीं चाहिए: न SMTP server, न mail profile, न दूसरा task।
आपको क्या मिलता है
- Task fail होने पर एक email, exit code और output की आख़िरी lines के साथ। वही alert Slack, Microsoft Teams, Discord, Google Chat, ntfy या webhook पर, और सहकर्मियों के addresses पर भी जा सकता है (देखें Alerts)।
- Task न चलने पर एक email: job का schedule task के trigger की तरह सेट करें (रोज़ 06:00 बजे, कार्यदिवसों पर, हर 2 घंटे …), और जब तय समय और grace तक कोई ping नहीं आता, तो job Missed (छूटा) हो जाता है। यही वह मामला है जो event-log trigger नहीं देख सकता।
- एक email जब यह सामान्य से बहुत ज़्यादा देर चलता है (Late, देर से), और एक जब यह वापस OK होता है।
अगर program fail होने पर भी 0 लौटाता है, तो wrapper यह नहीं बता सकता; इसकी जगह script के अंदर से रिपोर्ट करें, उदाहरण के लिए Python या R code से। ऐसा क्यों होता है, यह Task Scheduler 0x0 दिखाता है लेकिन script fail हुई पर है।
TaskBeacon के बिना
Task history चालू करें, Microsoft-Windows-TaskScheduler/Operational के event 201 पर trigger होने वाला एक task बनाएँ जिसमें non-zero ResultCode और task के नाम के लिए XML filter हो, और उससे एक PowerShell script चलवाएँ जो आपके SMTP server से mail भेजे (किसी mail library के साथ, क्योंकि Send-MailMessage obsolete है)। शुरू होने में fail होने वाले tasks के लिए event 101 पर दूसरा trigger जोड़ें। यह उस एक machine पर failures को कवर करता है। जो runs कभी होते ही नहीं, उनके लिए machine के बाहर कुछ चाहिए जो signal की उम्मीद रखे, और यही heartbeat check है।
क्या आपने Claude या ChatGPT को TaskBeacon से जोड़ा है? उससे पूछिए "कल रात क्या fail हुआ, और क्यों?" और वह आपके jobs के आधार पर जवाब देगा। यह कैसे काम करता है।
संबंधित
डॉक्स में: PowerShell (Task Scheduler) · Alerts · Schedules।
- Task Scheduler Last Run Result 0x0, लेकिन script fail हुईLast Run Result 0x0 का मतलब सिर्फ़ इतना है कि जिस program को चलाया गया उसने 0 लौटाया।
- पता करें कि कोई scheduled job चला ही नहींजो run हुआ ही नहीं, वह कोई error नहीं छोड़ता जिस पर alert हो।
- PowerShell script errors और Task Scheduler में exit codeNon-terminating errors exit code 0 छोड़ते हैं; -Command codes को 0 या 1 में बदल देता है।
TaskBeacon से शुरुआत मुफ़्त है; अभी हर feature सबके लिए खुला है और credit card की ज़रूरत नहीं। एक job बनाइए, code paste कीजिए, और पहला ping job के page पर दिख जाएगा।
मुफ़्त शुरू करें लाइव demo देखेंस्रोत
- Microsoft Learn: What's New in Task Scheduler (sendEmail और showMessage Windows 8 में deprecated) (31 मई 2018, अपडेट 11 मार्च 2025; अब भी यही मौजूदा page है)
- Microsoft Learn: Send-MailMessage (obsolete के रूप में चिह्नित) (18 जून 2024, अपडेट 16 जून 2026)
- Microsoft Learn (पिछले versions): Task Scheduler event IDs, जैसे 101 task start failed (लगभग 2009, पुराना: कोई मौजूदा page इन IDs की list नहीं देता)
- Microsoft Q&A: Task Scheduler job fail होने पर email alerts कैसे बनाएँ (send email option deprecated है) (26 अक्टूबर 2023, पुराना: माँग का संकेत)
- Microsoft Q&A: Task Scheduler से script schedule करना और email notification set up करना (2024-04-27)
इस page को इसके स्रोतों से 19 नवंबर 2026 को मिलाकर जाँचा गया। दूसरे products के menu और limits बदलते रहते हैं; अगर यहाँ कुछ अब मेल नहीं खाता, तो support@taskbeacon.io पर लिखें।