-
-
Save garmy-ja/e23d84ef185170072ed0e9831dfbdce3 to your computer and use it in GitHub Desktop.
CrystalDiskInfoの通知をWebhookに送るスクリプト群
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
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | |
$header.Add("Content-Type","application/json") | |
$GetEventLog = Get-EventLog -LogName Application -Newest 1 -Source CrystalDiskInfo | |
$EventLogM = "**CrystalDiskInfoから通知がありました** <!here> \r\nホスト名 : " + $Env:Computername + "\r\n通知日時 : " + [string]$GetEventLog.TimeGenerated + "\r\n通知内容 : " + [string]($GetEventLog.Message -replace '\r\n','') | |
$EventLogS = "*CrystalDiskInfoから通知がありました* <!here> \r\nホスト名 : " + $Env:Computername + "\r\n通知日時 : " + [string]$GetEventLog.TimeGenerated + "\r\n通知内容 : " + [string]($GetEventLog.Message -replace '\r\n','') | |
$requestM = @" | |
{ | |
"text": "$($EventlogM)" | |
} | |
"@ | |
$requestS = @" | |
{ | |
"text": "$($EventlogS)" | |
} | |
"@ | |
$BodyM = [System.Text.Encoding]::UTF8.GetBytes($requestM) | |
$BodyS = [System.Text.Encoding]::UTF8.GetBytes($requestS) | |
$Uri = "mattermostのwebhook" | |
Invoke-RestMethod -Uri $Uri -ContentType 'application/json' -Method Post -Header $header -Body $BodyM | |
$Uri = "Slackのwebhook" | |
Invoke-RestMethod -Uri $Uri -ContentType 'application/json' -Method Post -Header $header -Body $BodyS |
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
<QueryList> | |
<Query Id="0" Path="Application"> | |
<Select Path="Application">*[System[Provider[@Name='CrystalDiskInfo'] and (Level=3 or Level=4 or Level=0)]]</Select> | |
</Query> | |
</QueryList> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
タスクスケジューラで実行する内容は以下のようにする。
コマンド: powershell
引数: -ExecutionPolicy Bypass "(スクリプトのフルパス指定)"
スクリプトのたたき台として参考にしたページ
https://qiita.com/iwaohig/items/8853ed4433f6653396c2