Windows logo

With Windows 10’s PowerShell cmdlet, you can easily add applications to automatically trigger a VPN connection when they launch. Automating this task means you won’t even have to think about connecting to a VPN when you use certain apps.

To take advantage of this functionality in PowerShell, you’ll first have to add a VPN service to your computer if you don’t already have one.

RELATED: How to Connect to a VPN in Windows

How to Add VPN Auto-Triggering

After you set up a VPN connection on Windows 10, you’ll need to open an elevated instance of PowerShell. To do so, click the Start button, and then type “Powershell.” Right-click “Windows PowerShell,” and then select “Run as Administrator” from the menu.

Type "PowerShell" in the search bar, right-click "Windows PowerShell," and then click "Run as Administrator."

Click “Yes” in the prompt that appears to allow access to your computer.

In the PowerShell window, type the following and replace <VPNConnection> and <AppPath> with the name of the VPN connection, and the file path to the application you want to use, respectively:

Add-VpnConnectionTriggerApplication -Name "<VPNConnection>" –ApplicationID "<AppPath>"

The "Add-VpnConnectionTriggerApplication -Name "<VPNConnection>" –ApplicationID "<AppPath>" command in a PowerShell window.

Make sure you include the quotation marks in the command.

Press Enter to run the command. PowerShell warns you that split tunneling is disabled by default. To continue, you must confirm and enable the feature before it’s automatically triggered.

Type “Y” when the prompt appears, and then press Enter once more to finish.

The "Y" command to confirm split tunneling is disabled by default in a PowerShell window.

You have to enable split tunneling for the auto-trigger to connect to the VPN without human intervention.

Split tunneling stops Windows from routing all network traffic through the VPN when the application triggers it to start. Instead, it splits the traffic, and only the data from the application listed will flow through the VPN.

Type Set-VpnConnection -Name "<VPNConnection>" -SplitTunneling $True into PowerShell and replace <VPNConnection> with the name of your VPN (again, keep the quotes around it), and then press Enter.

The "Set-VpnConnection -Name "<VPNConnection>" -SplitTunneling $True" command in a PowerShell window. 

Next, in case you accidentally close the application and don’t want the connection to terminate, you can set a timeout buffer for you to restart the app.

Type Set-VpnConnection -Name "<VPNConnection>" -IdleDisconnectSeconds <IdleSeconds> into PowerShell and press Enter. Replace <VPNConnection> with the name of your connection and <IdleSeconds> with the number of seconds to wait until the connection terminates.

The "Set-VpnConnection -Name "<VPNConnection>" -IdleDisconnectSeconds <IdleSeconds>" command in a PowerShell window.

Now, when the application closes, Windows will wait 10 seconds before it terminates the VPN connection. You can make this number whatever you want or omit this step altogether.

How to See Which Applications Auto-Trigger a VPN

There are a few ways you can check to see which applications you’ve set to trigger the start of a VPN connection. You can either use a cmdlet inside PowerShell or edit the phonebook file in File Explorer.

RELATED: How PowerShell Differs From the Windows Command Prompt

If the VPN suddenly starts and you’re unsure why, you can use either of the following methods to pinpoint which application triggered it.

Using a PowerShell Cmdlet

To use this method, click the Start button and type “Powershell.” Right-click “Windows PowerShell,” and then select “Run as Administrator” from the menu.

Type "PowerShell" in the search bar, right-click "Windows PowerShell," and then click "Run as Administrator."

Click “Yes” in the prompt that appears to allow access to your computer.

In the PowerShell window, type the following command, but replace <VPNConnection > with the name of your VPN connection, and then press Enter:

Get-VpnConnectionTrigger -ConnectionName <VPNConnection>

The "Get-VpnConnectionTrigger -ConnectionName <VPNConnection>" command in a PowerShell window.

In our example, the command retrieved the trigger properties of the VPN connection “VPN Canada” and displayed them below.

Using File Explorer

The other option is to track down the dial-up phonebook file in File Explorer. You can open it in a text editor and see the list of applications that trigger the VPN.

A phonebook file provides a standard way for Windows to collect and specify the information it needs to establish a Remote Access Connection (RAS). The file contains information like IP addresses, ports, modem settings, and—the info we’re looking for—applications that trigger the connection.

To get started, open File Explorer and paste the following directory into the address bar, but replace <User> with the current username, and then press Enter:

C:\Users\<User>\AppData\Roaming\Microsoft\Network\Connections\Pbk

Paste the file path into the address bar.

Right-click “rasphone.pbk,” and then select the text editor in which you want to open the file.

Right-click "rasphone.pbk," and then select a text editor.

This one file contains all the VPN connections on your computer, so if you have more than one VPN, you might have to sift through a lot to find the applications you want. Each application is stored under the function “ClassicApplicationIDs” as its direct file path.

A list of "ClassicApplicationIds" in a text editor.

Luckily, if you don’t want to scroll to find each app, most text editors have a Find feature. Press Ctrl+F, type “ClassicApplicationIds” in the text field, and then press Enter.

"ClassicApplicationIds" in a Find text box.

How to Remove VPN Auto-Triggering

If you accidentally add the wrong application or no longer want the VPN to trigger when you launch specific apps, you can remove them using a similar cmdlet in PowerShell.

RELATED: Geek School: Learning to Use Cmdlets in PowerShell

To remove VPN auto-triggering, click the Start button, and then type “Powershell.” Right-click “Windows PowerShell,” and then select “Run as Administrator” from the menu.

Type "PowerShell" in the search bar, right-click "Windows PowerShell," and then click "Run as Administrator."

Click “Yes” in the prompt that appears to allow access to your computer.

In the PowerShell window, type the following, but replace <VPNConnection> and <AppPath> with the name of your VPN connection and the path to the application, respectively:

Remove-VpnConnectionTriggerApplication -Name "<VPNConnection>" –ApplicationID "<AppPath>"

PowerShell prompts you to confirm you want to remove the application from the auto-trigger list. Type “Y” and press Enter.

"Y" confirming the deletion of an auto-trigger in a PowerShell window.

Repeat this step for every application you want to remove from the list.


Now, when you launch the applications you specified, Windows will initiate a VPN connection and send their traffic through it—no third-party software required.

Brady Gavin Brady Gavin
Brady Gavin has been immersed in technology for 15 years and has written over 150 detailed tutorials and explainers. He's covered everything from Windows 10 registry hacks to Chrome browser tips. Brady has a diploma in Computer Science from Camosun College in Victoria, BC.  
Read Full Bio »

The above article may contain affiliate links, which help support How-To Geek.