VPN Auto Connect

Welcome Forums General PowerShell Q&A VPN Auto Connect

Viewing 1 reply thread
  • Author
    • #226797
      Topics: 1
      Replies: 0
      Points: -8
      Rank: Member

      we have a meraki client vpn, which has no client vpn software. we use windows 10 built in vpn. i used powershell script below (and a batch file) to auto connect the vpn.

      1. is there way to add a condition in where the attempt to connect to vpn isnt made if the computer lan/wifi is in the office and already behind the meraki?

      2. also, a way to hide the credentials in the script? below it lists in plain text.

      3 lastly, notify user if the vpn is not connected?


      while ($true)
                  $vpnname = "YOURVPNCONNECTIONNAME"
                  $vpnusername = "YOURUSERNAME"
                  $vpnpassword = "YOURPASSWORD"
                  $vpn = Get-VpnConnection -AllUserConnection | where {$_.Name -eq $vpnname}
                  if ($vpn.ConnectionStatus -eq "Disconnected")
                      $cmd = $env:WINDIR + "\System32\rasdial.exe"
                      $expression = "$cmd ""$vpnname"" $vpnusername $vpnpassword"
                      Invoke-Expression -Command $expression 
                  start-sleep -seconds 30
    • #226812
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      Daniel, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.



Viewing 1 reply thread
  • You must be logged in to reply to this topic.