PingStatus

  



-->

  1. Ping Status Codes
  2. Powershell Ping Status
  3. Wmic Win32_pingstatus
  4. Ping Status Tool

If your using XP/2003+ (this includes Vista/2008/7), then you can use the Win32PingStatus.The machines inwhich is running the script code is the only system which needs to be XP/2003+, and it works just like using Ping.exe, only it's not using ping.exe so it should act as a loophole to your security setting which does not allow the execution of ping.exe. .so.or I can understand this paragraphe (test-connection and another class like win32diskdrive or win32pingstatus are members of System.Management.ManagementObject#rootcimv2.) or it was difference in previous powershell version (v3,v2)? Why use test-connection before wmi technology sice are members of the same namespaces?

The Win32PingStatus WMI class represents the values returned by the standard ping command. More information on ping can be found in RFC 791. Lets ping PC01 from PowerShell, execute this command: Get-WmiObject -Class Win32PingStatus -Filter 'Address='PCO1' or in a brief notation. Gwmi Win32PingStatus -Filter 'Address='PCO1' Command output.

Sends ICMP echo request packets, or pings, to one or more computers.

Syntax

Description

The Test-Connection cmdlet sends Internet Control Message Protocol (ICMP) echo request packets, orpings, to one or more remote computers and returns the echo response replies. You can use thiscmdlet to determine whether a particular computer can be contacted across an 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 time-out and number of pings, and to configure theconnection and authentication.

Unlike the familiar ping command, Test-Connection returns aTestConnectionCommand+PingStatus object that you can investigate in PowerShell. The Quietparameter returns a Boolean value in a System.Boolean object for each tested connection. Ifmultiple connections are tested, an array of Boolean values is returned.

Examples

Example 1: Send echo requests to a remote computer

This example sends echo request packets from the local computer to the Server01 computer.

Test-Connection uses the TargetName parameter to specify the Server01 computer. The IPv4parameter specifies the protocol for the test.

A series of TestConnectionCommand+PingStatus objects are sent to the output stream, oneobject per ping reply from the target machine.

Example 2: Send echo requests to several computers

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

Example 3: Use parameters to customize the test command

This example uses the parameters of Test-Connection to customize the command. The local computersends a ping test to a remote computer.

Test-Connection uses the TargetName parameter to specify Server01. The Count parameterspecifies three pings are sent to the Server01 computer with a Delay of 2-second intervals.

You might use these options when the ping response is expected to take longer than usual, eitherbecause of an extended number of hops or a high-traffic network condition.

Example 4: Run a test as a background job

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

The Start-Job command uses the Test-Connection cmdlet to ping many computers in an enterprise.The value of the TargetName parameter is a Get-Content command that reads a list of computernames from the Servers.txt file. The command uses the Start-Job cmdlet to run the command as abackground job and it saves the job in the $job variable.

The Receive-Job command is instructed to -Wait until the job is completed, and then gets theresults and stores them in the $Results variable.

Example 5: Create a session only if a connection test succeeds

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

The Test-Connection cmdlet pings the Server01 computer, with the Quiet parameter provided.The resulting value is $True if any of the four pings succeed. If none of the pings succeed,the value is $False.

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

Example 6: Use the Traceroute parameter

Introduced in PowerShell 6.0, the Traceroute parameter maps a route between the local computerand the remote destination you specify with the TargetName parameter.

The Test-Connection command is called with the Traceroute parameter. The results, which are[Microsoft.PowerShell.Commands.TestConnectionCommand+TraceStatus] objects, are output tothe Success output stream.

Parameters

Specifies the size, in bytes, of the buffer sent with this command. The default value is 32.

Type:Int32
Aliases:Size, Bytes, BS
Position:Named
Default value:32
Accept pipeline input:False
Accept wildcard characters:False

Specifies the number of echo requests to send. The default value is 4.

Type:Int32
Position:Named
Default value:4
Accept pipeline input:False
Accept wildcard characters:False

Specifies the interval between pings, in seconds.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

This parameter sets the Don't Fragment flag in the IP header. You can use this parameter withthe BufferSize parameter to test the Path MTU size. For more information about Path MTU, see thePath MTU Discovery article in wikipedia.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
PingStatus

Forces the cmdlet to use the IPv4 protocol for the test.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Forces the cmdlet to use the IPv6 protocol for the test.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Sets the maximum number of hops that an ICMP request message can be sent. The default value iscontrolled by the operating system. The default value for Windows 10 is 128 hops.

Type:Int32
Aliases:Ttl, TimeToLive, Hops
Position:Named
Default value:128 hops in Windows 10
Accept pipeline input:False
Accept wildcard characters:False

This parameter is used to discover the Path MTU size. The cmdlet returns a PingReply#MTUSizeobject that contains the Path MTU size to the target. For more information about Path MTU, see thePath MTU Discovery article in wikipedia.

Type:SwitchParameter
Aliases:MtuSizeDetect
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Causes the cmdlet to do a ping test. This is the default mode for the Test-Connection cmdlet.

Type:SwitchParameter
Position:Named
Default value:True
Accept pipeline input:False
Accept wildcard characters:False

The Quiet parameter returns a Boolean value. Using this parameter suppresses allerrors.

Each connection that's tested returns a Boolean value. If the TargetName parameterspecifies multiple computers, an array of Boolean values is returned.

If any ping to a given target succeeds, $True is returned.

If all pings to a given target fail, $False is returned.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Ping Status Codes

Causes the cmdlet to send ping requests continuously. This parameter can't be used with theCount parameter.

Type:SwitchParameter
Aliases:Continuous
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Causes the cmdlet to attempt to resolve the DNS name of the target. When used in conjunctionwith the Traceroute parameter, the DNS names of all intermediate hosts will also beretrieved, if possible.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Specifies the names of the computers where the ping originates. Enter a comma-separated list ofcomputer names. The default is the local computer.

Note

This parameter is not supported in PowerShell versions 6 and up. Supplying this parametercauses an error.

Type:String
Position:Named
Default value:Local computer
Accept pipeline input:False
Accept wildcard characters:False

Specifies the computer(s) to test. Type the computer names or type IP addresses in IPv4 or IPv6format.

Type:String[]
Aliases:ComputerName
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

Specifies the TCP port number on the target to be used in the TCP connection test. The cmdlet willattempt to make a TCP connection to the specified port on the target.

If a connection can be made, $True will be returned.

If a connection cannot be made, $False will be returned.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Powershell Ping Status

Sets the timeout value for the test. The test fails if a response isn't received before the timeoutexpires. The default is five seconds.

This parameter was introduced in PowerShell 6.0.

Type:Int32
Position:Named
Default value:5 seconds
Accept pipeline input:False
Accept wildcard characters:False

Causes the cmdlet to do a traceroute test. When this parameter is used, the cmdlet returns aTestConnectionCommand+TraceStatus object.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

You can't pipe input to this cmdlet.

Outputs

Wmic Win32_pingstatus

TestConnectionCommand+PingStatus, TestConnectionCommand+TraceStatus, Boolean, TestConnectionCommand+PingMtuStatus

Vbscript

By default, Test-Connection returns a TestConnectionCommand+PingStatus object for eachping reply.

If you specify the Traceroute parameter, the cmdlet will return aTestConnectionCommand+TraceStatus object for each ping reply along the route.

If you specify the Quiet or TcpPort parameters, it returns a Boolean value. Ifmultiple connections are tested, an array of Boolean values is returned.

Ping Status Tool

Related Links