4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【備忘録】イベントログ検知→メール送信メモ

Last updated at Posted at 2017-11-22

イベントログへのERROR出力をメール通知

Powershellスクリプトを作成

Sendmail.ps1
# イベントログへのERROR出力でメール通知

## Powershellスクリプトを作成

# SMTPサーバ
$smtp = "xxx.xxx.xxx.xxx"
# Fromアドレス
$from = "xxxxxx@xxxxxx"
# Toアドレス
$to = "yyyyy@yyyyyyy"
# Subject
$subject = "エラー通知"

# SmtpClientクラス
$mlClient = New-Object Net.Mail.SmtpClient($smtp)

# MailMessageクラス
$mailMsg = New-Object Net.Mail.MailMessage($from, $to)
$mailMsg.Subject = $subject
$mailMsg.Body = "イベントログでエラー検知`nイベントID:1000"
$mailMsg.SubjectEncoding = [System.Text.Encoding]::GetEncoding("ISO-2022-JP")
$mailMsg.BodyEncoding = [System.Text.Encoding]::GetEncoding("ISO-2022-JP")

# メール送信
$mlClient.Send($mail)

Powershellをコールするbatを作成

Sendmail.bat
rem Sendmail.ps1 配置場所に移動
cd /d D:\temp
powershell -NoProfile -ExecutionPolicy Unrestricted .\sendmail.ps1

タスクスケジューラにイベント登録

event.png

イベント発火

eventcreate /ID 1000 /L Application /SO Cmd /T ERROR /D "Error event"

4
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?