PowerShell for Windows Admins

Aug 22 2011   1:03PM GMT

Ping a subnet

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I recently needed to find which IP addresses were active on a subnet to track down a printer. Quickest way was to ping them.

function ping-subnet {            
param (            
0..255 | foreach {             
 $address = "$subnet.$_"            
 if (Test-Connection -ComputerName $address -Count 1 -Quiet){            
    Test-Connection -ComputerName $address -Count 1            

Put the subnet in as a parameter. Then work through 0 – 255 building an address from the subnet. use test-connection in quiet mode and if it responds do a 1 count test-connection (ping) to get the result.

Not necessarily the quickest but it was quick to throw together and it works

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: