@ECHO OFF REM Run App MyApp.exe data.ini > MyApp.out 2>&1 echo EXIT_CODE : %errorlevel% REM Check exit code if %errorlevel% NEQ 0 ( echo ErrorLevel is "%errorlevel%" GOTO Error ) REM Check valid output find /i "Result=Pass" MyApp.out if %errorlevel% NEQ 0 ( echo Result : Fail GOTO Error ) echo Result : Pass GOTO End :Error Powershell .\sendmail.ps1 EXIT /B -1 :End EXIT /B 0 @ECHO ON
The next code is powershell script that sends email. It creates various .NET objects related to mail and set their properties as we do in other languages like C#. If SMTP server is valid server name and client credential is valid, the mail will be delivered via SMTP.
# # sendmail.ps1 # $from = New-Object system.net.mail.MailAddress "sender@live.com" $to = New-Object system.net.mail.MailAddress "receiver@live.com" $message = new-object system.net.mail.MailMessage $from, $to $message.Subject = "[FAILED] Scheduled Task Failed" $message.Body = "Scheduled Task failed on Machine1. Please investigate the failure." $smtpserver = "smtphost.domain.com" $client = new-object system.net.mail.smtpclient $smtpserver $client.UseDefaultCredentials = $TRUE $client.Send($message)
No comments:
Post a Comment