Skip to content

Instantly share code, notes, and snippets.

@SeidChr
Created March 18, 2020 20:42
Show Gist options
  • Save SeidChr/43a3252ed9a1c50aad7cacccc6997835 to your computer and use it in GitHub Desktop.
Save SeidChr/43a3252ed9a1c50aad7cacccc6997835 to your computer and use it in GitHub Desktop.
windows based vpn automatic reconnect
param($vpnName)
rasdial $vpnName /disconnect
param($vpnName)
while($true) {
# get the connection again, otherwise the status is not refreshed
$vpn = Get-VpnConnection -Name $vpnName
Write-Host $vpn.ConnectionStatus
if ($vpn.ConnectionStatus -eq "Disconnected") {
rasdial $vpnName
# double the sleep time after a connect
Start-Sleep -Seconds 30
}
Start-Sleep -Seconds 30
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment