$ToastText01 = [Windows.UI.Notifications.ToastTemplateType, Windows.UI.Notifications, ContentType = WindowsRuntime]::ToastText01
$c = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetTemplateContent($ToastText01)
$c.SelectSingleNode('//text[@id="1"]').InnerText = 'インターネットが壊れてない'
$i = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
ping -t 8.8.8.8 | % { echo $_; if ( $_.Contains("からの応答") ) { [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($i).Show($c) } }
オフラインでQiita開けないので、上のスクリプトをローカルに保存した方がいいです
実行例
PS C:\Users\Admin> ping -t 8.8.8.8 | % { echo $_; if ( $_.Contains("からの応答") ) { [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($i).Show($c) } }
8.8.8.8 に ping を送信しています 32 バイトのデータ:
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
8.8.8.8 からの応答: バイト数 =32 時間 =8ms TTL=115
8.8.8.8 からの応答: バイト数 =32 時間 =7ms TTL=115
8.8.8.8 からの応答: バイト数 =32 時間 =6ms TTL=115
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
ping: 転送に失敗しました。一般エラーです。
設定から無効有効にして動作確認できます