Script to keep Hamachi alive

We use hamachi by logmein at work for various things, but one of the problems with hamachi at times is sometimes the tunneling engine doesn’t start. Now previously I had created a batch file that did this job, but it was pieced together with code I found online. So overall it was complicated.

So I wanted to redo it in powershell as well  make it give some kind of message in case someone else was needing to run this script.

So here it is

while ($true) {

if (-not (Test-Connection '192.168.0.207' -Quiet)) {

Write-Host "Test failed: $(Get-Date -Format "MM/dd hh:mm tt")"

Write-Host "Restarting Hamachi..." -ForegroundColor Red

Restart-Service Hamachi2Svc
Start-Sleep -Seconds 60

}

else {

Write-Host "Connection test passed: $(Get-Date -Format "MM/dd hh:mm tt")"

Start-Sleep -Seconds 600

}

}

It does need to be ran as an admin and I’ve got it set up as scheduled task for when the computer reboots.

The line that says

Start-Sleep -Seconds 60

is how long it will wait for hamachi to restart before it tries again. In my case it seems 60 seconds is plenty of time, but you may want to bump the time up a bit if needed.

Leave a Reply

Your email address will not be published. Required fields are marked *