This script updates the qbittorrent port from the port that PIA returns from its port forwarding if one is available.
This currently only does something if qbittorrent is open and running since it updates through the Web UI. There is commented code that could be changed to utilize the qbittorrent cli to change the port when the application is closed.
This requires that you have qbittorrent's web interface enabled with the "Bypass authentication for clients on localhost" enabled.
- Save the script
update qbittorrent forward port from pia.ps1
to somewhere you'll know where it is for later- I put mine under
C:\scripts\update-qbittorrent-forward-port-from-pia.ps1
- Note: The steps below will use the above location as an example
- I put mine under
- Open Task Scheduler
- Create a new folder for organization if you would like (Action -> New Folder).
- Save the XML file below:
Update Qbittorrent Forward Port from PIA.xml
- Open Task Scheduler
- Import Task (right click -> Import Task, or Action -> Import Task)
- Note: this may require you to have the script saved at:
C:\scripts\update-qbittorrent-forward-port-from-pia.ps1
- Note: this may require you to have the script saved at:
- Create New Task
- Give it a meaningful name, maybe even a description
- General -> Security Options
- ☑️ Run whether user is logged on or not
- ☑️ Do not store password
- ☑️ Run with highest privledges
- ☑️ Run whether user is logged on or not
- Triggers -> New
- Begin the task: On an event (you can watch the event log for when you toggle the VPN connection)
- Settings
- Basic
- Log: Microsoft-Windows-NetworkProfile/Operational
- Source: NetworkProfile
- Event ID: 10000
- Basic
- Actions -> New
- Action: Start a program
- Settings
- Program/script: powershell
- Add arguments: -ExecutionPolicy Bypass -File "C:\scripts\update-qbittorrent-forward-port-from-pia.ps1"
- Note: change the path to wherever you saved your script