How to wait and start over? RRS feed

  • Question

  • Hi,

    I have tinkered lightly with powershell and I'm finally really trying to do something useful with it.  My users are a "challenge" to say the least and cannot be relied upon to actually connect the openvpn client without being yelled at.  I'd like to find a way to execute a powershell script through a scheduled task at startup that first checks to see there is a working internet connection, if there isn't, wait 10 minutes and start over, if there is a working connection, see if the vpn server can be contacted, if it can, wait 10 minutes and start over, if not, then execute a batch file silently that starts the vpn. 

    I created a batch to exe and it runs silently and starts the vpn properly if run from command line

    I'm stuck on the how to "wait 10 minutes and start over" in the nested if statements or even if my nested if statements are correct.  Here is what I have so far, any input or help is appreciated.  Hopefully I'm posting this in the right place. 

    #check if computer has internet connection if (Test-Connection -computer -quiet) { #if is true then test if vpn is up if (!(Test-Connection -computer -quiet)) { # if true wait 10 minutes and run again } Else {Set-Location "C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\" Start-Process tscvpnstart.exe } }

    Else { #wait 10 minutes and run again }

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:46 PM This is not "develop custom solutions for me" forum
    Wednesday, September 12, 2018 11:26 PM

All replies

  • A task can be set to "wait for network".  That is all you need to do.

    The correct way to start a VPN is this:

    Set task  program to 'C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\tscvpnstart.exe'

    Set task to "Wait For Network"

    There is no need to use PowerShell.


    • Edited by jrv Thursday, September 13, 2018 8:27 AM
    Wednesday, September 12, 2018 11:49 PM
  • That only solves part of the problem though, the other objective was to detect if the vpn was down and if so restart it.  How would I do that in Task Scheduler?
    Thursday, September 13, 2018 12:30 PM