LoginSignup
0
0

More than 1 year has passed since last update.

POWERSHELL PINGを指定IPに出し続ける、グリッドビューで確認

Posted at

1.jpg
2.jpg

# 黒い画面を閉じる
powershell -WindowStyle Hidden -command "exit"
# INPUTBOXのおまじない
[void][System.Reflection.Assembly]::Load("Microsoft.VisualBasic, Version=8.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")

# pingを実行する宛先を指定する
$targets = [Microsoft.VisualBasic.Interaction]::InputBox("IPを入力してください(例)10.10.10.10","pingを出し続けます")

# 設定
# pingを実行する間隔(ミリ秒)
$interval = 500

# 繰り返し数
$repeat   = 100

@(1..$repeat) | foreach {
    $targets | foreach {
        # 間隔をあけるためのsleep
        Start-Sleep -Milliseconds $interval
        try {
            # ping実行
            $tc = Test-Connection $_ -count 1 -ErrorAction Stop

            #結果の格納
            $result = "○"
        } catch [Exception] {
            # 失敗した場合
            $result = "×"
        }
        # 現在時刻
        $datetime = Get-Date -F "yyyy/MM/dd HH:mm:ss.fff"

        # CSV形式で結果情報を作成
        $row = $result + "," + $datetime  + "," + $tc.Address + "," + $tc.ResponseTime 

        # CSVからオブジェクトを出力
        $row | ConvertFrom-Csv -Header @("Result","DateTime","Target","ResponseTime(ms)")
    }

} | Out-GridView -Title "Ping Results" # グリッドビューを表示する


0
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
0
0