# 黒い画面を閉じる
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" # グリッドビューを表示する
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme