取得 Windows 事件日誌中的錯誤的通知

取得 Windows 事件日誌中的錯誤的通知

我編寫了一個 powershell 腳本來製作資料庫轉儲,我計劃使用 Windows 任務計劃程式每晚執行該轉儲。它輸出到日誌文件,以便我可以確保一切正常,但我希望在出現問題時得到通知,而無需手動檢查日誌。我的想法是為此腳本和其他自訂腳本建立 Windows 事件日誌,並讓它們都在其中記錄錯誤。當此日誌中發生錯誤時,我希望以某種方式收到通知,例如透過向我發送電子郵件。有沒有辦法做到這一點?我運行的是 Windows 7。

答案1

試一試。您可以定義日誌的位置、錯誤代碼是什麼等。如果你想使用gmail發送訊息,我前段時間看到了一個教學。我相信你能找到它。

Try
{
Database dump commands
}
Catch
{
    Write-EVentLog -LogName Application -Source "Baller Script" -EntryType Error -EventID 42 -Message "There has been a failure..."
    Send-MailMessage -From [email protected] -To [email protected] -Subject "DBDump is broke as hell! (Event ID: 42)" -SmtpServer [email protected]
    Break
}

相關內容