このエントリーをはてなブックマークに追加


PowerShellでPingができるTest-Connectionコマンドレットを紹介します。


関連記事

Test-Connectionでpingをしてみる・Test-Connection

Test-Connectionコマンドレットを使用すると、PowerShellで簡単にPingを実現できます。
以下に使用例を記します。

  • yahoo.co.jpにpingしてみる
    以下のようにPingした結果が返却されます。
    PS C:\> Test-Connection yahoo.co.jp
    
    Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
    ------        -----------     -----------      -----------                              -----    --------
    WINPC         yahoo.co.jp     183.79.135.206                                            32       41
    WINPC         yahoo.co.jp     183.79.135.206                                            32       147
    WINPC         yahoo.co.jp     183.79.135.206                                            32       66
    WINPC         yahoo.co.jp     183.79.135.206                                            32       206
  • google.co.jpにPingしてみる
    PS C:\> Test-Connection google.co.jp
    
    Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
    ------        -----------     -----------      -----------                              -----    --------
    WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       52
    WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       48
    WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       43
    WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       64

Pingする回数を指定する方法

オプション -Count を使用すればPingする回数を指定することができます。

PS C:\> Test-Connection google.co.jp -Count 1

Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
------        -----------     -----------      -----------                              -----    --------
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       125


PS C:\> Test-Connection google.co.jp -Count 10

Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
------        -----------     -----------      -----------                              -----    --------
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       63
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       51
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       65
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       97
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       52
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       89
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       95
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       127
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       250
WINPC         google.co.jp    172.217.26.3     2404:6800:4004:80d::2003                 32       131

Pingによる応答の有無を確認したい場合

Pingによる応答があったかどうかを確認したい場合は、-Quiet を使うと簡単に実現できます。
TrueまたはFalseが返却されます。
以下に実行例を記します。

  • ping応答あり
    PS C:\> Test-Connection just4fun.biz -Quiet
    True
    
    PS C:\> Test-Connection just4fun.biz -Quiet -Count 1
    True
  • ping無応答
    PS C:\> Test-Connection foo.just4fun.biz -Quiet -Count 1
    False

以上、PowerShellのTest-Connectionコマンドレットを使用してPingを実現する方法でした。



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-05-16 (水) 23:30:06