Hem > IT, Microsoft, PowerShell, Tips > Very simple PowerShell ICMP-monitor

Very simple PowerShell ICMP-monitor

While working from home I discovered that from time to time either my ISP or my employer vpn solution sometimes drop packets…which is annoying to say the least. Especially if you’ve been working for a very long time with some documentation and suddenly realize that you’re unable to save it…..

So, I hacked this together in PowerShell so that I at least get an alert when something is wrong with the connection:

$monSrv = 'myFavoriteServerOnTheCompanyNetwork'
$icmpInterval = 10

Add-Type -AssemblyName PresentationFramework

while($true) {
      if(!(Test-Connection -ComputerName $monSrv -BufferSize 16 -Count 1 -ea 0 -quiet)) {
      [System.Windows.MessageBox]::Show("Cannot reach "+$monSrv)
   } else {
      Write-Host "Monitoring "$monSrv"..."
      sleep $icmpInterval

This while-loop will run for indefinitely, or until it’s either paused by an alert or halted by you.

There are probably better ways of doing this, but this is one way to do it.

Categories: IT, Microsoft, PowerShell, Tips Taggar:
  1. Inga kommentarer än.