Created
September 30, 2021 15:04
-
-
Save mlaffargue/a19e916acb46c16d1d116126e7d119f9 to your computer and use it in GitHub Desktop.
Powershell: Check VPN connexion, auto-reconnect if disconnected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
# 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