Attempting to clean up VPN connections, but cannot remove profile specific connections. Is there a way to find all VPN connections including the ones not in the global catalog?

When covid hit, everyone scrambled to get a VPN connection to every PC in the org. Eventually we wrote a script that got put into GPO to create an alluserconnection VPN connection on each PC to one of 3 devices based on where they were located around the state.

Now I have been tasked with creating a script that removes all VPN connections from all PCs and replace them with a single uniformly named connection. I have the main script written to remove everything except the one we want, but it will not get profile specific connections since i run the scirpt as me and cannot see VPNs that were added without the alluserconnection switch. And if i put the script into GPO, it will run as system.

Is there a way to get any and all connections on a PC or perhaps run the script as the current/last logged on user to grab those as well?

Here is the script i have so far, maybe it will help someone even if i dont get an answer.

#Get all VPNs that do not match the correct one using the -AllUserConnection switch

$VPNs = Get-VpnConnection -AllUserConnection | where {$_.name -ne “TheOne”}

#check for a connection that matches the name of the new VPN

$theOne = Get-VpnConnection -AllUserConnection | where {$_.name -eq "TheOne"}

#Clean up any other VPN connections that may be installed for whatever reason

$VPNothers = Get-VpnConnection

#Remove all other AllUserConnection VPNs (like the various ones added for WFH) that are not the new one

foreach ($vpn in $VPNs)

{

Remove-VpnConnection -AllUserConnection $vpn.name -Force -PassThru

}

#Remove any other VPNs that may be installed on the PC

foreach ($vpnOther in $VPNothers)

{

Remove-VpnConnection $vpnother.name -Force -PassThru

}

#If $theOne is not present on the machine, it will get added

if(!$theOne)

{

Add-VpnConnection -AllUserConnection -Name "TheOne" blah blah blah, all that good stuff here -RememberCredential $false -Force -PassThru

}

If you drop the -AllUserConnection parameter, you can run a copy of the above in the local context as a user login script or scheduled task.

Since you say you don’t want any user vpns left. You could just push a gpo to copy a blank file to %appdata%\Microsoft\Network\Connections\PPbk\rasphone.pbk there by killing any VPN connections users have.

True, there is already a bit in there that runs without the alluserconnection to remove. I guess i need to get an OU to test this on and see if it works

%appdata%\Microsoft\Network\Connections\PPbk\rasphone.pbk

thank you! if running the script as a login script doesnt work, this is an excellent option! Thank you for pointing me to where the file actually lives!

Just so i know for future reference, where is the global catalog located?