Filter Out Unavailable Servers

Even PowerShell v.1 has remarkable remoting capabilities--as long as you can make sure the target systems are online. Otherwise, you run into lengthy network timeouts. Here is a quick filter you can use to filter lists with IP addresses and computer names. Check-Online will only let those pass a pipeline that can be pinged successfully:

filter Check-Online {
trap { continue }

. {
$obj = New-Object system.Net.NetworkInformation.Ping
$result = $obj.Send($_, 1000)
if ($result.status -eq 'Success') { $_ }
}
}

Check out how this works:

"127.0.0.1","noexists","powershell.com" | Check-Online

Twitter This Tip! ReTweet this Tip!


Posted Oct 23 2009, 08:00 AM by ps1

Comments

uberVU - social comments wrote Social comments and analytics for this post
on 10-25-2009 8:24 AM

This post was mentioned on Twitter by PowerTip: Filter Out Unavailable Servers with #PowerShell http://bit.ly/Yrg5e

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.