VPN Auto Connect

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
        }

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.

https://social.technet.microsoft.com/Forums/en-US/9ac62252-7880-4f16-a116-1c0ce5f41280/vpn-auto-connect?forum=winserverpowershell

Thanks

Is there a VPN that you recommend for using on a home router? I want to keep anyone using my network safe. I also researched some articles about VPN.

Robert, 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!.

Please do not hijack other peoples threads. If you have a question about Powershell code you wrote yourself you should create a new question for yourself.

Sorry to me, please. And thank you. I appreciate rules and you.