stylesheet

2010-02-12

イベントログのエラーをGrowl for Windowsで通知 (Windows7)

Windows7でイベントログにエラーログが追加された場合にGrowl for Windowsへ通知を行う方法のメモ。

  1. 以下、コンピューターの管理を使用する。
  2. イベントビューアーを使用して通知を行いたいログにタスクを設定する。
  3. タスクスケジューラのイベントビューアータスクに新しいタスクが作成されているのでプロパティからトリガーを編集する。
  4. カスタムを選択して、イベントフィルターの編集を行う。

Growlへ通知を行うPowerShellスクリプト

PowerShellでは、デフォルトでスクリプトの実行が無効になっているため、Set-ExecutionPolicyコマンドレットを実行してスクリプトの実行を許可する。

PS > Set-ExecutionPolicy RemoteSigned
# 最後のイベントエラーとワーニングをGrowl for Windowsに通知
# USAGE: notify-last-event-error.ps1 [logname]
param ($logname = "application")
$e = Get-EventLog -LogName $logname -EntryType Error,Warning -Newest 1
if ($e) {
    $t = [String]::Format("{0}: Event Log", $e.EntryType)
    $m = [String]::Format("EventID: {0}\nSource: {1}\n{2}", $e.InstanceId, $e.Source, $e.Message)
    & "C:\Program Files\Growl for Windows\growlnotify.exe" /t:$t $m
}