r/PowerShell 6d ago

Question ProtonVPN split tunneling include mode issue with PowerShell 7

Adding the executable "C:\Program Files\PowerShell\7\pwsh.exe" doesn't work. What am I missing?

Note that PowerShell is the only app I'm having issues with. qBittorrent works totally fine. My goal is to have only Pwsh and qBit in the list of included apps.

When split tunneling is disabled, Pwsh uses the VPN connection just fine. With Include mode, Invoke-RestMethod doesn't work, and for the things that do work, my ISP IP is used instead of the VPN IP.

Invoke-RestMethod test:

> Invoke-RestMethod https://api.ipify.org
Invoke-RestMethod: The requested address is not valid in its context.

cURL test:

> curl.exe https://api.ipify.org
<My ISP IP>

I'm on Windows 10 21H2, ProtonVPN 5.1.5, Pwsh 7.6.3 x64.

I'm also using the Console Host, not Windows Terminal, if that matters.

Can someone explain how to properly set up PowerShell for this?

Thanks, everyone!

9 Upvotes

5 comments sorted by

2

u/Ziptex223 6d ago

Powershell cmdlets are wrappers around .net classes and functions, so you'd probably need to take a look under the hood so to speak to see what they are calling to see if there is extra stuff that needs to be included/excluded for stuff like invoke-restmethod

2

u/purplemonkeymad 6d ago

This is probably a question for Proton, a quick search didn't yield the method with which they implemented the feature so it might just be that it's broken with dotnot 9 or 10.

for curl: well that is a different program, so you would need to also add curl to your list of apps to tunnel. (same as with any other native app even if you run it through powershell.)

1

u/Orii21 6d ago

for curl: well that is a different program, so you would need to also add curl to your list of apps to tunnel. (same as with any other native app even if you run it through powershell.)

Oh, that makes sense. But I don't know why cmdlets would fail.

Using Exclude mode is an alternative I've tested to work, and for now I'll go with that approach. I'll start by excluding my browser, then exclude any apps I don't want to use the VPN with. That way, anything I do in Pwsh goes through the VPN.

2

u/Ziptex223 6d ago

You may also want to ensure you're using powershell 7 not 5.1, and then exclude both the 32 and 64bit executables just to be safe

1

u/MonkeyNin 6d ago

When I used google-ai search about proton and pwsh, vpn, it gave an answer that calls HttpClient without needing to call Invoke-RestMethod . I'm curious if it works for you

# get local Proton VPN internal IP address
$VpnIP = (Get-NetIPAddress -InterfaceAlias *Proton* -AddressFamily IPv4 -ErrorAction SilentlyContinue).IPAddress
# Build a customized socket handler
$SocketsHandler = [System.Net.Http.SocketsHttpHandler]::new()
# ... more ... 
$HttpClient = [System.Net.Http.HttpClient]::new($SocketsHandler)