I say – Let’s go all Microsoft ! 😀
Microsoft has enabled us to create our own Applications and Functionalities using Powershell, Moreover it made all our IT experiences manageable from a centralized console.
So idea of using a third party tool sounds a bit old fashioned 😛 to me , Lets make this Blog post a Good Bye to the Tools available over internet to Ping multiple computers in a ‘FANCY‘ manner and make – ‘One of Our Own’ .
IDEA :
Tweak the Test-Connection cmdlet available in powershell and make it Presentable with extended functionalities such as Colors, Host Status, Success and Failure Percentage, Number of ICMP Attempts.
HOW IT WORKS :
STEP 1 : Create a function that accepts Values as an Parameter, just like other Cmdlets.
STEP 2 : Initialize Array objects that would be used for the Calculation depending upon ICMP response.
STEP 3 : Run an infinite loop and output the Header row on the screen
STEP 4 : Now Pass each Hostname to the ForEach Block to test the Connectivity, Calculate and Display the coloured Output depending upon the ping response.
Please note, Quiet switch with Test-Connection only gives $true and $false values depending upon the Ping response.
Test-Connection $_ -Count 1 -Quiet
STEP 5 : At the end please Pause the script execution for few seconds, so that screen doesn’t gets refreshed with the new values very quickly and are easy on eyes 🙂
HOW TO RUN IT :
Compile the function once and then you can run this Ping-Host utility in many ways, like in the screenshot below.
OUTPUT :
Post executing the script you will get coloured output depending upon the ping response you receive from the host.
Click on below link highlighted in GREEN to Auto-Download the complete Powershell script
COMPLETE SCRIPT : Ping-Host
Hopefully this script comes handy to you and useful in maintenance and other troubleshooting purposes.
Happy Reading Folks 🙂
Prateek Singh
Related posts
5 Comments
Leave a ReplyCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,133,558 People Reached
Just a question, what is your attachment a word document rather than a ps1 or txt
WordPress doesn’t supports .PS1 extension files to be uploaded.
Whoa quite a lot of amazing material! http://www.streaksahead.co.za/UserProfile/tabid/738/userId/131295/Default.aspx
Excellent multi host ping output table script. I’m surprised how well the cmdlet test-connection works as it is known to be less reliable than the .Net class, or WMI/CIM methods. You get an A+ in my book.
Awesome Script. I’ve been trying to automate an email showing the failed hosts, but can’t get it to work. THis is what i have done starting at the Send-mail line. Can you help?
#Print status DOWN in RED if above condition is met
Write-Host “| $_$(Make-Space $_.Length $Maximum)| DOWN$(Make-Space 4 4) | $SuccessPercent`%$(Make-Space ([string]$SuccessPercent).length 6) | $FailurePercent`%$(Make-Space ([string]$FailurePercent).length 6) | $($Total[$i])$(Make-Space ([string]$Total[$i]).length 9)|” -BackgroundColor Red
{Send-MailMessage -Subject “$_ is down” -SmtpServer 192.168.1.44 -to noreply@cssf.com -from PingScript@cssf.com `
-Body Write-Host “| $_$(Make-Space $_.Length $Maximum)| DOWN$(Make-Space 4 4) | $SuccessPercent`%$(Make-Space ([string]$SuccessPercent).length 6) | $FailurePercent`%$(Make-Space ([string]$FailurePercent).length 6) | $($Total[$i])$(Make-Space ([string]$Total[$i]).length 9)|” -BackgroundColor Red
}
$i++
}