PowerShell Logo Small

Test-Connection



This is the built-in help made by Microsoft for the command 'Test-Connection', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Sends ICMP echo request packets ("pings") to one or more computers.

SYNTAX


Test-Connection [-ComputerName] <String[]> [-AsJob] [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-BufferSize
[<Int32>]] [-Count [<Int32>]] [-Delay [<Int32>]] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-ThrottleLimit [<Int32>]] [-TimeToLive [<Int32>]] [<CommonParameters>]
Test-Connection [-ComputerName] <String[]> [-Source] <String[]> [-AsJob] [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy |
Unchanged}] [-BufferSize [<Int32>]] [-Count [<Int32>]] [-Credential [<PSCredential>]] [-Delay [<Int32>]] [-Impersonation {Default | Anonymous | Identify | Impersonate |
Delegate}] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-ThrottleLimit [<Int32>]]
[-TimeToLive [<Int32>]] [<CommonParameters>]
Test-Connection [-ComputerName] <String[]> [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-BufferSize [<Int32>]]
[-Count [<Int32>]] [-Delay [<Int32>]] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-InformationAction {SilentlyContinue | Stop | Continue |
Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Quiet] [-TimeToLive [<Int32>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Test-Connection cmdlet sends Internet Control Message Protocol (ICMP) echo request packets ("pings") to one or more remote computers and returns the echo response
replies. You can use this cmdlet to determine whether a particular computer can be contacted across an Internet Protocol (IP) network.


You can use the parameters of Test-Connection to specify both the sending and receiving computers, to run the command as a background job, to set a timeout and number of
pings, and to configure the connection and authentication.


Unlike the traditional "ping" command, Test-Connection returns a Win32_PingStatus object that you can investigate in Windows PowerShell, but you can use the Quiet parameter
to force it to return only a Boolean value.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293926
Add-Computer
Restart-Computer
Stop-Computer

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>Test-Connection Server01

Source Destination IPV4Address IPV6Address Bytes Time(ms)
------ ----------- ----------- ----------- ----- --------
ADMIN1 Server01 157.59.137.44 32 0
ADMIN1 Server01 157.59.137.44 32 0
ADMIN1 Server01 157.59.137.44 32 0
ADMIN1 Server01 157.59.137.44 32 1



This command sends echo request packets ("pings") from the local computer to the Server01 computer. This command uses the ComputerName parameter to specify the Server01
computer, but omits the optional parameter name.






-------------------------- EXAMPLE 2 --------------------------

PS C:\>Test-Connection -ComputerName Server01, Server02, Server12



This command sends pings from the local computer to several remote computers.






-------------------------- EXAMPLE 3 --------------------------

PS C:\>Test-Connection -Source Server02, Server12, localhost -ComputerName Server01 -Credential Domain01\Admin01



This command sends pings from different source computers to a single remote computer, Server01. It uses the Credential parameter to specify the credentials of a user who has
permission to send a ping request from the source computers. Use this command format to test the latency of connections from multiple points.






-------------------------- EXAMPLE 4 --------------------------

PS C:\>Test-Connection -ComputerName Server01 -Count 3 -Delay 2 -TTL 255 -BufferSize 256 -ThrottleLimit 32



This command sends three pings from the local computer to the Server01 computer. It uses the parameters of Test-Connection to customize the command.

Use this command format when the ping response is expected to take longer than usual, either because of an extended number of hops or a high-traffic network condition.






-------------------------- EXAMPLE 5 --------------------------

PS C:\>$job = Test-connection -ComputerName (Get-Content Servers.txt) -asjob
PS C:\>if ($job.JobStateInfo.State -ne "Running") {$Results = Receive-Job $job}



This example shows how to run a Test-Connection command as a Windows PowerShell background job.

The first command uses the Test-Connection cmdlet to ping many computers in an enterprise. The value of the ComputerName parameter is a Get-Content command that reads a list
of computer names from the Servers.txt file. The command uses the AsJob parameter to run the command as a background job and it saves the job in the $job variable.

The second command checks to see that the job is not still running, and if it is not, it uses a Receive-Job command to get the results and store them in the $Results
variable.






-------------------------- EXAMPLE 6 --------------------------

PS C:\>Test-Connection Server55 -Credential Domain55\User01 -Impersonation Identify



This command uses the Test-Connection cmdlet to ping a remote computer. The command uses the Credential parameter to specify a user account with permission to ping the
remote computer and the Impersonation parameter to change the impersonation level to "Identify".






-------------------------- EXAMPLE 7 --------------------------

PS C:\>if (Test-Connection -ComputerName Server01 -Quiet) {New-PSSession Server01}



This command creates a session on the Server01 computer only if at least one of the pings sent to the computer succeeds.

The command uses the Test-Connection cmdlet to ping the Server01 computer. The command uses the Quiet parameter, which returns a Boolean value, instead of a Win32_PingStatus
object. The value is $True if any of the four pings succeed and is, otherwise, $False.

If the Test-Connection command returns a value of $True, the command uses the New-PSSession cmdlet to create the PSSession.