Skip to content

Instantly share code, notes, and snippets.

@mlaffargue
Created September 30, 2021 15:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mlaffargue/a19e916acb46c16d1d116126e7d119f9 to your computer and use it in GitHub Desktop.
Save mlaffargue/a19e916acb46c16d1d116126e7d119f9 to your computer and use it in GitHub Desktop.
Powershell: Check VPN connexion, auto-reconnect if disconnected
#===============================================================================
# FILE: auto-reconnect-vpn.ps1
#
# DESCRIPTION: Automatically reconnect a named VPN which has been disconnected.
#
# AUTHOR: Laffargue Michael
# VERSION: 1.0.0
# LICENSE: MIT License
#===============================================================================
# Name of the VPN connexion
$vpnName="myVPN"
# Check VPN status frequency in seconds
$checkFrequency=10
while($true)
{
$conn=$(Get-VpnConnection -Name $vpnName).ConnectionStatus
if ($conn -eq 'Disconnected') {
rasdial $vpnName
}
sleep $checkFrequency
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment