Powershell – Rename VPN Connections via Powershell

powershellvpnwindows-8.1

I'm trying to batch rename vpn connections on my Windows 8.1 machine. I have no trouble modifying the server address with Set-VpnConnection, but I can't find a way to rename a vpn connection:

First there is no Rename-VpnConnection cmdlet, and I don't know how to make Rename-Item to work with Vpn Connection object (if it will ever work); Second, I tried to use ServerAddress rather than Name to identify a vpn connection but powershell told me that it's not allowed; Then I tried to add the new name directly after the -Name argument like this:

Set-VpnConnection -Name "MyVPN" "New Name to MyVPN"

Powershell runs the command silently without error, but didn't take effect at all. Please let me know if this is possible in Powershell and if not, any other programmatic way to do it? Thanks!

Best Answer

Benny! I tried to rename VPN on Windows 7 using cmd,netsh,wmic and powershell and only one easy way that I have found was this way.

By default VPN is a INI file with extension .PBK and it located at C:\ProgramData\Microsoft\Network\Connections\Pbk

So you can rename it using BAT file or CMD

powershell -Command "(gc C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk) -replace '[Old name]', '[New name]' | Out-File C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk"
taskkill /im "explorer.exe" /f
start "" "explorer.exe"