4

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!

Benny
  • 143
  • 1
  • 4

2 Answers2

0

I could not figure out a way to test the VPN cmdlets on my system, but here is a guess of how you could achieve the end result with a workaround, let's say you do a Get-VPNConnection and filter out the name of the connection you want to rename, then you pipe it to Export-CSV and save it to a file, edit the file and change the field for name with your desired new name, save the file, then Import-CSV the modified file and pipe it to Add-VPNConnection, like I said, this is all guesswork since I wasn't able to test it, but it's worth to try, since it won't take much time, regards.

AnGut_IT
  • 11
  • 3
  • 1
    Thanks @AnGut_IT for the tip. However this will not work because when you re-import with `Add-VpnConnection` cmdlet, all the vpn credentials is lost since it's not exported by `Get-VpnConnection`. – Benny Dec 28 '15 at 08:20
  • Thanks for the feedback @Benny, too bad that won't work, hope you find the answer, even if the answer is it can't be done easily. – AnGut_IT Dec 29 '15 at 04:46
0

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"
kgimpel
  • 207
  • 1
  • 6
  • 1
    Thank you @kgimpel for pointing me to the rasphone.pbk file! Although in my situation(Windows 8.1) the file is located under \AppData\Roaming\Microsoft\Network\Connections\Pbk. I didn't know the profile was even stored in plain text which will make things much simpler! And by the way, on my machine I don't even have to restart explorer to allow the change to take effect. – Benny Jan 14 '16 at 16:20