# VPN Auto Connect

**URL:** <https://forums.powershell.org/t/vpn-auto-connect/14354>\
**Category:** PowerShell Help\
**Created:** [May 8, 2020, 3:22pm UTC](https://forums.powershell.org/t/vpn-auto-connect/14354 "2020-05-08T15:22:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bove11](https://avatars.discourse-cdn.com/v4/letter/b/b9bd4f/32.png) [@bove11](https://forums.powershell.org/u/bove11)\
**Post date:** [May 8, 2020, 3:22pm UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/1 "2020-05-08T15:22:54Z")

</div>

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?

&nbsp;

```
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
        }
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 8, 2020, 6:34pm UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/2 "2020-05-08T18:34:50Z")

</div>

Daniel, welcome to [Powershell.org](http://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!](https://powershell.org/forums/topic/read-me-before-posting-youll-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](https://social.technet.microsoft.com/Forums/en-US/9ac62252-7880-4f16-a116-1c0ce5f41280/vpn-auto-connect?forum=winserverpowershell)

Thanks

---

<div class="post-metadata">

**Author:** ![robertsl](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@robertsl](https://forums.powershell.org/u/robertsl)\
**Post date:** [June 4, 2020, 5:35am UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/3 "2020-06-04T05:35:20Z")

</div>

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](https://webguidevpn.com/best-vpn-for-porn/) articles about VPN.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 4, 2020, 6:15am UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/4 "2020-06-04T06:15:33Z")

</div>

Robert, welcome to [Powershell.org](http://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!](https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did).

> [@](#):
>
> Is there a VPN that you recommend for using on a home router? I want to keep anyone using my network safe.

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.

---

<div class="post-metadata">

**Author:** ![robertsl](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@robertsl](https://forums.powershell.org/u/robertsl)\
**Post date:** [June 4, 2020, 1:59pm UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/5 "2020-06-04T13:59:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/vpn-auto-connect/14354/6 "2024-05-16T20:30:06Z")

</div>

Closed on May 16, 2024, 8:30pm UTC


