PowerShell

PowerShell: Endless Ping with Test-Connection (Test-Endless)

If you look up how a ping can be done endlessly with Test-Connection, you will usually find solution with a while loop or something else complicated. The dilemma is that ping provides the -t parameter, but Test-Connection only provides the Count parameter and this parameter requires a value and there is no endless parameter. It’s cumbersome to enter a high value every time the command is executed. Why not use the int32 MaxValue field to provide a high value so that the ping is running endlessly?

Here we go.

Int32::MaxValue


Test-Connection sid-500.com -Count ([int32]::MaxValue)

1.png

Okay, I can already hear your words: “Hey, hold on. It’s even more complicated now, now I’m supposed to enter these cryptic characters?”

Read on. Now we’ll make a small but fine function out of it. I will call it Test-Endless.

Test-Endless


function Test-Endless {

[CmdletBinding()]

param
(

[Parameter(Mandatory=$true)]
$Target

)

Test-Connection $Target -Count ([int32]::MaxValue)

}

17.png

Feel free to omit the target parameter.

1.png

How to use it

Copy the code into your PowerShell ISE session and run the code. Then type the command and have fun with it.

If you want to make the function permanently available, so that the function is there every time you start PowerShell, you have to create a folder in C:\Program Files\WindowsPowerShell\Modules. Name it Test-Endless. Then save the code as a .psm1 file in that folder.  The screenshot below should be a help.

1.png

See you next time with PowerShell.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.