На самом деле я хочу добиться следующих трех вещей в моем файле Master.bat:
1. Collect and redirect all the entries of ‘Application’ event log to an output file.
2. Search for a specific error message “The system cannot find the file specified” in Application event log and append the whole error message line to a log file.
3. Send an Email notification to alert me about the error message found on daily basis.
Мастер.bat
wevtutil qe Application >D:\test\Applog.txt
findstr /i /c:"The system cannot find the file specified" "D:\test\Applog.txt" > "D:\test\errorlog.txt"
PowerShell.exe -file D:\test\Mail.ps1 %1 %2
Mail.ps1
if (Select-String -Path D:\test\Applog.txt -pattern "The system cannot find the file specified")
{
function sendMail{
Write-Host "Sending Email"
$smtpServer = "smtp.domain.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "[email protected]"
$msg.To.Add("[email protected] ")
$msg.subject = "Error found in log"
$msg.body = "please check there is a known error in Application log."
$smtp.Send($msg)
}
sendMail
}
else
{write-host "nothing to process"}
Проблема, с которой я здесь сталкиваюсь, заключается в том, что, к сожалению, в журнале Applog.txt остается тонна данных для просмотра, и когда я планирую Master.bat, я получаю уведомления по электронной почте для сообщений об ошибках, которые произошли много дней назад, чего я не хочу. Я хочу получать уведомления по электронной почте с сообщением об ошибке только на текущую сегодняшнюю дату.
Может ли кто-нибудь помочь мне здесь?