he following code will ping a certain address for you, the IP address that is stored in the $IpAddress
variable. If this adress is not reachable by ping. The network adapter will be reset. Change the ip address variable to your own valid value.
rename 'Name of the connection' to the used network adapter interface name. Example: 'Ethernet'
$IpAdress = "192.168.0.1"
$ConnectionName = "ethernet"
$Testconnection = test-connection $IpAdress -count 1 -quiet
if(!$Testconnection)
{
$nic = gwmi win32_networkadapter -filter "NetConnectionID='$ConnectionName'"
$nic.disable()
write-host "Disabling Network interface '$ConnectionName''"
sleep 5
$nic.enable()
write-host "Enabling Network interface '$ConnectionName''"
}
Try configuring a scheduled task for the script to run every X of time to check the adapter connectivity. Or just run the script with powershell when you notice the connection is lost.
I dont know if disabling/enabling your network adapter will reconnect the VPN connection, so you might need to tweak the code a bit, though I think this will get you started in the right direction.
Ping
class to check the availability of a printer. I also showed him the Windowsping.exe
command, for scripting the job if needed. I'll just have to find out how to reconnect now.