Today With PowerShell – Saturday, 14th May 2016

I quite often find myself waiting for a remote computer to reboot. I’ve used the venerable ping –t hostname option to keep an eye on things in the past but I thought it was about time that I found a PowerShell way to do it. Test-Connection is the cmdlet, I thought, but it doesn’t have an equivalent of ping’s –t option. In the end I came up with an approach that I think works.

while ( Test-Connection –count 1 –delay 15 –Quiet –ComputerName hostname –eq $false)  { Write-Host “Reboot complete” }

What this is doing is running Test-Connection once every 15 seconds in Quiet mode, until it gets a result. This returns a boolean (True/False) rather than a Win32_PingStatus object. A boolean is easier to test for using a while loop. Not quite as snappy as ping, but I can wrap this in a script and have the command block execute something more interesting than Write-Host, such as sending an email or producing a popup.

This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s