Quick Hits: Ping Sweep One Liner

So I was curious as to how many active ip addresses I had on my network and didn’t feel like manually typing “ping <ipaddress>” and wait for it to timeout and then “rinse and repeat”.  Along comes Test-Connection and the –quiet  and –count switches that allow me to make one attempt and then return a True/False status on whether the ip is active or not.

I then decided that this would make a great one liner that would list out the IP address I am testing followed by the True/False status. 

As you can see, it’s a pretty simple one liner that can quickly show you what is active.

1..20 | % {"192.168.1.$($_): $(Test-Connection -count 1 -comp 192.168.1.$($_) -quiet)"}

Capture

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell and tagged , , . Bookmark the permalink.

3 Responses to Quick Hits: Ping Sweep One Liner

  1. Mike Currier says:

    This worked wonderfully!! Thanks!!

  2. Josiah says:

    Could you point me to where I can learn a bit more about the syntax you used in that command. It looks like it could be real handy to understand that well. Thanks!

  3. Pingback: For Loops for Fun and Profit | Pivots n Divots

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 )

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