Ping in the PowerShell


PowerShell ICMP Ping with Test-Connection

Ping on Windows 10 is no longer limited to running from the Command Prompt, but ping in the PowerShell offers additional possibilities. The Test Connection cmdlet in PowerShell 7 includes advanced features such as Repeat and Traceroute or as a ping process in the background.

Test Connection

Examples with Test-Connection

The Test Connection cmdlet sends Internet Control Message Protocol (ICMP) Echo request packets to one or more comma-separated remote hosts and returns the Echo responses.

With the -Repeat option, as is known from Ping, ICMP requests are sent to the specified host until the end of the operation, by entering CTRL+BREAK.

This example shows how to run a test connection command as a PowerShell background job.

Route Tracking – Traceroute with the test connection in the PowerShell.

The Traceroute parameter introduced in PowerShell 6.0 arranges route tracking between the local computer and the remote destination specified by parameters.

In another example, parameters are used to customize the Test Connection command. The local computer sends a ping test to a remote computer.

This cmdlet is available from PowerShell 6.0 and later.

Test-Connection TCP Port Parameters

The -TcpPort parameter specifies the TCP port number to the destination to use in the TCP connection test. The cmdlet attempts to establish a TCP connection with the specified port to the destination.

If a connection can be established, $True is returned. If a connection cannot be established, $False is returned. The Paramter-TcpPort is available from PowerShell 7.0 and later.

Test-Connection MTU Size Parameters

The -MtuSize parameter is used to determine the path MTU size.

The cmdlet returns a PingReply-MTUSize object that contains the MTU size path to the target, it is available from PowerShell 7.0 and later.

Test-Connection Parameter Quiet

The -Quiet parameter returns a Boolean value. Using this parameter suppresses all errors.

This cmdlet is available from PowerShell 7.0 and later.

PowerShell Remoting Test-Connection

The next example creates a session to Server2 if at least one of the pings sent to the computer succeeds. To do this, you must configure TrustedHosts on the remote computer.

To use HTTP for PowerShell remoting, run the following command on the remote host from an administrator-opened (cmd) Command Prompt.

The TrustedHosts configuration setting is done by running winrm.cmd with the config/client option on the remote host.

Questions of are accepted. The query for the Global Configuration of WinRM is as follows.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *