Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## run infinite ping test to given address & output details including success/failure & time
- ## This variant beeps on error
- $lastFailure=$null;[int]$fails=0;[int]$everySeconds = 30 ;. { while(1){ $started = [datetime]::now ; $r = tnc -Computer 192.168.0.43 -WarningAction SilentlyContinue | select @{n='Date';e={$started}},computername,RemoteAddress,PingSucceeded,@{n='RTT (ms)';e={$_.PingReplyDetails.RoundtripTime}},@{n='Ttl';e={$_.PingReplyDetails.Options.ttl}},@{n='Failures';e={$fails}},@{n='Last Failure';e={$lastfailure}},InterfaceAlias; $r ; if( -not $r.PingSucceeded ) { $fails++ ; $lastfailure = $started ; [console]::Beep( 3000 , 1000 ) } ; if( ($sleep = $everySeconds - ([datetime]::Now - $started).TotalSeconds ) -gt 0 ) { Start-Sleep -Seconds $sleep }}} | ft
- ## This variant displays a modal dialogue but only 1 at a time & using jobs so loop doesn't hang waiting on dialogue closure
- $null = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic");$jobby = $null ;$lastFailure=$null;[int]$fails=0;[int]$everySeconds = 30 ;. { while(1){ $started = [datetime]::now ; $r = tnc -Computer 192.168.0.43 -WarningAction SilentlyContinue | select @{n='Date';e={$started}},computername,RemoteAddress,PingSucceeded,@{n='RTT (ms)';e={$_.PingReplyDetails.RoundtripTime}},@{n='Ttl';e={$_.PingReplyDetails.Options.ttl}},@{n='Failures';e={$fails}},@{n='Last Failure';e={$lastfailure}},InterfaceAlias; $r ; if( -not $r.PingSucceeded ) { $fails++ ; $lastfailure = $started ; if( -Not $jobby -or $jobby.State -ine 'running' ) { $jobby | Remove-Job -Force -ea 0 ; $jobby = Start-Job -Scriptblock { [Microsoft.VisualBasic.Interaction]::MsgBox("Ping failed to $($using:r.ComputerName) @ $(($using:r).date.toString('G'))" , 'OKOnly,SystemModal,Exclamation' , 'Ping Failure' )}}} ; if( ($sleep = $everySeconds - ([datetime]::Now - $started).TotalSeconds ) -gt 0 ) { Start-Sleep -Seconds $sleep }}}|ft
- ## This variant pads the last failure column so that it displays the full date/time (crude but works although output object missing LastFailure)
- $null = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic");$jobby = $null ;$lastFailure=$null;[int]$fails=0;[int]$everySeconds = 30 ;. { while(1){ $started = [datetime]::now ; $r = tnc -Computer 192.168.0.44 -WarningAction SilentlyContinue | select @{n='Date';e={$started}},computername,RemoteAddress,PingSucceeded,@{n='RTT (ms)';e={$_.PingReplyDetails.RoundtripTime}},@{n='Ttl';e={$_.PingReplyDetails.Options.ttl}},@{n='Failures';e={$fails}},InterfaceAlias; $r ; if( -not $r.PingSucceeded ) { $fails++ ; $lastfailure = $started ; if( -Not $jobby -or $jobby.State -ine 'running' ) { $jobby | Remove-Job -Force -ea 0 ; $jobby = Start-Job -Scriptblock { [Microsoft.VisualBasic.Interaction]::MsgBox("Ping failed to $($using:r.ComputerName) @ $(($using:r).date.toString('G'))" , 'OKOnly,SystemModal,Exclamation' , 'Ping Failure' )}}} ; if( ($sleep = $everySeconds - ([datetime]::Now - $started).TotalSeconds ) -gt 0 ) { Start-Sleep -Seconds $sleep }}}|ft -Property *,@{e={$lastFailure};Label='Last Failure '}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement