Skip to content

Instantly share code, notes, and snippets.

@garmy-ja
Last active July 6, 2024 03:37
Show Gist options
  • Save garmy-ja/e23d84ef185170072ed0e9831dfbdce3 to your computer and use it in GitHub Desktop.
Save garmy-ja/e23d84ef185170072ed0e9831dfbdce3 to your computer and use it in GitHub Desktop.
CrystalDiskInfoの通知をWebhookに送るスクリプト群
$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
<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>
@garmy-ja
Copy link
Author

garmy-ja commented Jul 5, 2024

タスクスケジューラで実行する内容は以下のようにする。

コマンド: powershell
引数: -ExecutionPolicy Bypass "(スクリプトのフルパス指定)"

スクリプトのたたき台として参考にしたページ
https://qiita.com/iwaohig/items/8853ed4433f6653396c2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment