Continuing on with my exploring of testing connectivity I ran into a practical reason today for using Powershell. A computer on my employers network apparently loses network connectivity (according to the end user) during a 2 hour window in the evening. The event logs on the PC don’t indicate any issues and the network logs also don’t indicate any problems and there are no scheduled tasks set to run on the PC.
I started out thinking about setting off a constant test-connection / ping but realised this would not time stamp any drops.
Then I thought about adding in the timestamps. At first I thought this might be a good solution but then considered the waste of log space. A solution to this came to me; setting a scheduled task to run the test-connection / ping then I thought the same thing must be possible through scripting PowerShell and it is!
Below is my solution (it will need saving as a PowerShell script):
—————
“Ping at a certain time!”
“”
“This script will ping a host at the time you select.”
$computertag = Read-Host -Prompt ‘Please type (or paste) full computer tag’
$timetorun = Read-Host -Prompt ‘Please type (in 24hr HH:MM format, e.g. 13:20)’
$howlongtorun = Read-Host -Prompt ‘How many pings should I send? 2 = 20 seconds, 6 = 1 minute, 12 = 2 minutes, 60 = 10 minutes, 360 = 1 hour’
do {
Start-Sleep 1
}
until ((Get-Date) -ge (Get-Date “13:20″))
$connect = test-connection $computertag -count $howlongtorun -delay 10 | format-table @{n=’Date/Time’;e={Get-Date}}, Address, ProtocolAddress, ResponseTime | out-file c:\temp\”$computertag”.txt -append
——————
$computertag
$timetorun
$howlongtorun
are all variables that use Read-Host to receive input from the user, so that others could use the script. Future improvements I am considering would be a prompt for the delay and possibly outputting to a CSV so that the date could easily be shown in a line graph.