PowerTip: Test Connectivity to Remote Servers without Ping


Summary: Use Windows PowerShell to test connectivity to remote servers without using Ping.

Hey, Scripting Guy! Question How can I test connectivity to remote servers to ensure my Windows PowerShell scripts will work if I
           have the Packet Internet Grouper (PING) blocked at the firewall?

Hey, Scripting Guy! Answer Use Test-WsMan, for example:

's1','s2' | % {Test-Wsman $_}

Comments (4)

  1. Chen V says:

    In catch block change the $_.Message to $_.Exception.Message

    Output
    wsmid :
    http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
    ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
    ProductVendor : Microsoft Corporation
    ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

    wsmid :
    http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
    ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
    ProductVendor : Microsoft Corporation
    ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

    http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859193" Machine="
    L06081.corporateroot.net">The WinRM client cannot process the request because the server name
    cannot be resolved.

    wsmid :
    http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
    ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
    ProductVendor : Microsoft Corporation
    ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

  2. Chen V says:

    $servers = Get-Content C:TempSystem.txt
    foreach($server in $servers)
    {
    try{
    $Server | Test-WSMan -ErrorAction Stop
    }catch{$_.Message;continue;}
    }

  3. Very good. So we can have get-content from a txt file and pipe it to Test-WsMan. I will like yo know the result. How can I use it in Try, Catch error jangling!

  4. Chen V says:

    We don’t need Foreach here the computername parameter accepts pipleline values
    ‘S1’ , ‘S2’ | Test-WSMan

Skip to main content