VPN Triggers

Ok, so I realize this post won't apply to most people, but I want to share this just in case it can save someone hours of digging for VPN PowerShell commands.   The other day I found myself with a strange request from a client, they wanted to push out a VPN connection profile from Intune, and enable it so that it always stays connected when the PC has an internet connection.  We the short version of the story is I have not done a full deployment of always on, the 2nd part of the story is they wanted to use the VPN connection as the primary network connection of the currently non-domain joined machines 200+.  To make a long story short I wasn't able to get the simple certificate services to enroll intune joined user certificates to connect to the internal PKI infrastructure as it failed to autoenroll with a very detailed error.  "NO DATA".  So welcome to plan B.

B-Plan was a simple L2TP connection using the same RAS, NPS server.  One a profile was built and tested there were a couple tweaks we had to make to ensure that they could connect, join the domain, reboot and still have the option to connect to the VPN for 1st sign in.

The fun bit of this was to get the connection to always connect when on the internet to "protect" the users from themselves when not at work.  The solution is below.

#creates the connection
Add-VpnConnection -name "<MYDomain>VPN" -serverAddress "alwayson.<MYDomain>.com" -tunneltype "L2tp" -L2tpPsk "<MYPSK>" -dnsSuffix "<MYDomain>.com" -AuthenticationMethod Eap -force

#Tells the connection to remember credentials
Get-VpnConnection "<MYDomain>VPN" | Set-VpnConnection -RememberCredential $true

#Adds triggers when user starts applications (Can modify as desired)
Add-VpnConnectionTriggerApplication -ConnectionName "<MYDomain>VPN" -ApplicationID "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -force
Add-VpnConnectionTriggerApplication -ConnectionName "<MYDomain>VPN" -ApplicationID "C:\Program Files(x86)\internet explorer\iexplore.exe" -force
Add-VpnConnectionTriggerApplication -ConnectionName "<MYDomain>VPN" -ApplicationID "C:\Program Files\internet explorer\iexplore.exe" -force
Add-VpnConnectionTriggerApplication -ConnectionName "<MYDomain>VPN" -ApplicationID "C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe" -force

#Sets the connection to be available on the Ctrl-alt-delete screen
get-Vpnconnection -alluserconnection | set-vpnconnection -alluserconnection -force


The order is is specific.  You cannot add triggers to a VPN connection created with the -alluserconnection flag.  Make the changes 1st then convert it.

Comments

Popular posts from this blog

Integrate Choco with SCCM

Windows 11 22H2 production setup!

Automate Server Patching with Puppet (Part 2)