1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

インターネットに接続できたら通知【PowerShell】

Last updated at Posted at 2023-08-30
$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: 転送に失敗しました。一般エラーです。

設定から無効有効にして動作確認できます

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?