Skip to content

Instantly share code, notes, and snippets.

@enxt
Forked from 01000101/fix-gp-routes.ps1
Created December 15, 2022 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enxt/1e6aeaabdb5b3ab5461ee8d01b20d0aa to your computer and use it in GitHub Desktop.
Save enxt/1e6aeaabdb5b3ab5461ee8d01b20d0aa to your computer and use it in GitHub Desktop.
PowerShell script to remove unwanted "full tunnel" Palo Alto GlobalProtect VPN routes.
# Description name of the GlobalProtect interface
$gp_iface = "PANGP Virtual Ethernet Adapter"
# Routes to remove from the GlobalProtect interface
$bad_routes = @(
'0.0.0.0/0',
'10.1.10.0/24',
'10.1.10.255/32',
'172.16.100.0/24',
'192.168.1.0/24')
# How many loops used to remove routes.
# GlobalProtect will re-add routes if this value is too low.
$loop_count = 5
# Sleep time per loop, in seconds (decimal)
$sleep_time = 1
Write-Output "Finding GlobalProtect interface index..."
$gp_idx = (Get-NetAdapter -InterfaceDescription $gp_iface).IfIndex
Write-Output "GlobalProtect interface index: $gp_idx"
Write-Output "Dumping GlobalProtect routes..."
Get-NetRoute -InterfaceIndex $gp_idx
Write-Output "Removing bad routes..."
For ($i = 0; $i -le $loop_count; $i++ ) {
foreach ($route in $bad_routes ) {
try {
Remove-NetRoute -DestinationPrefix $route -InterfaceIndex $gp_idx -Confirm:$false -ErrorAction Stop
Write-Output "+ Deleted route: $route"
}
catch { }
}
Start-Sleep -Seconds $sleep_time
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment