Created
August 13, 2018 20:30
-
-
Save nyanshiba/d9c78b908f9c6f220888225ab3b8a761 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#180719 | |
#タイトルバーに表示 | |
(Get-Host).UI.RawUI.WindowTitle="startup" | |
#====================ユーザ設定==================== | |
#--------------------Twitter-------------------- | |
#ruby.exe | |
$ruby_path='C:\Ruby24-x64\bin\ruby.exe' | |
#tweet.rb | |
$tweet_rb_path='C:\DTV\EDCB\tweet.rb' | |
#SSL証明書(環境変数) | |
$env:ssl_cert_file='C:\DTV\EDCB\cacert.pem' | |
#--------------------Discord-------------------- | |
#webhook url | |
$hookUrl='https://discordapp.com/api/webhooks/XXXXXXXXXX' | |
#====================スタートアップ==================== | |
#ロック | |
rundll32.exe user32.dll,LockWorkStation | |
#アプリケーション | |
C:\DTV\EDCB\EpgTimer.exe | |
#Audio関連のプロセス優先度を高にするやつ | |
Start-Process -FilePath "powershell" -Verb runAs -ArgumentList "-WindowStyle Hidden -command `"C:\DTV\bin\AudioPriority.ps1`"" | |
#====================content==================== | |
#予め現在の日付時刻を整形して変数に格納しておく | |
$MyDateTime=(Get-Date).ToString("yy/MM/dd (ddd) HH:mm") | |
#録画用アプリの起動を待つ | |
Start-Sleep -s 30 | |
#ネットワーク接続の確認とループ | |
while (!(Test-Connection google.co.jp -Quiet -Count 1)) { | |
Start-Sleep -s 10 | |
#ネットワークが切断されていた=停電発生? | |
$env:content="`nError:ネットワークの切断を検出" | |
} | |
#内容 | |
$env:content="${MyDateTime}に鯖が再起動しました${env:content}" | |
#再起動時に予約があると録画用アプリが即起動するので(自動変数を使いたい) | |
switch ((Get-Process -ErrorAction 0 'EpgDataCap_bon').Count) { | |
#再起動後すぐに録画用アプリが起動している=録画失敗? | |
{$_ -ge 1}{$env:content+="`nError:録画失敗の可能性($_)"} | |
} | |
#1日前までの重大ログをソート | |
#Get-WinEvent System | ?{$_.Level -eq 1} | Format-List -Property * | |
$env:content+="`n"+'```'+(Get-WinEvent -FilterHashtable @{Logname="System";Level=1;StartTime="$((Get-Date).AddDays(-1))"} -ErrorAction SilentlyContinue | Select TimeCreated,Id,LevelDisplayName,ProviderName | Out-String)+'```' | |
#====================Twitter==================== | |
&"$ruby_path" "$tweet_rb_path" | |
#====================Discord==================== | |
#オブジェクト作成 | |
$payload=[PSCustomObject]@{ | |
content = $env:content | |
} | |
#JSONに変換 | |
$payload=($payload | ConvertTo-Json) | |
#Byte型に変換 | |
$payload=[System.Text.Encoding]::UTF8.GetBytes($payload) | |
#投稿 | |
Invoke-RestMethod -Uri $hookUrl -Method Post -Body $payload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment