Created
August 31, 2016 08:45
-
-
Save nakaji/3d84623ce4c7477fae9209ec43058182 to your computer and use it in GitHub Desktop.
Azure Cloud Backupの実行結果確認通知(メール)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Azure Cloud Backupの実行結果確認通知(メール) | |
# | |
# 基本設定 | |
$from = "admin@example.com" | |
$to = "caution@example.com" | |
$password = "xxxx" | |
$smtp = "smtp.example.com" | |
$port = "587" | |
# 当日のイベントログ取得 | |
$events = Get-WinEvent CloudBackup | ?{ $_.TimeCreated.ToString("yyyyMMdd") -eq [DateTime]::Now.ToString("yyyyMMdd")} | |
# 件名の編集 | |
$status = "正常" | |
$events | ?{ $_.LevelDisplayName -eq "警告" } | %{ $status="警告" } | |
$events | ?{ $_.LevelDisplayName -eq "エラー" } | %{ $status="エラー" } | |
$subject = "【${status}】AzureBackup結果通知" | |
# 本文の編集 | |
$body = "{0,-19} {1,2} {2,-16} {3}`n" -f "TimeCreated","Id","LevelDisplayName","Message" | |
$events | %{ $body += "{0,-19} {1,2} {2,-16} {3}`n" -f $_.TimeCreated,$_.Id,$_.LevelDisplayName,$_.Message } | |
$subject | |
$body | |
# メール送信 | |
$sc = New-Object Net.Mail.SmtpClient($smtp, $port) | |
$sc.Credentials = New-Object Net.NetworkCredential($from, $password) | |
$sc.Send($from, $to, $subject, $body) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment