0

I have a point-to-site VPN connection configured on 30+ client machines and I just had to change the VPN gateway's address. Of course, that means I have to reconfigure all of the client machines. Rather than do it manually, I was hoping I could create some kind of program or script that I could run which would update things automatically. The only thing I need to change is the server address, everything else should stay the same.

I came across these PowerShell commands Get-VpnConnection and Set-VpnConnection. I can successfully retreive the created VPN connection using this command:

Get-VpnConnection MyConnectionName -AllUserConnection

So I tried using the Set variant:

Set-VpnConnection -Name MyConnectionName -ServerAddress NewServerAddress -AllUserConnection

But this simply returns and does nothing. No error, no effect. Checking the server address with rasphone shows that the old address is still being used.

I can also do this:

$connection = Get-VpnConnection MyConnectionName -AllUserConnection
$connection.ServerName = NewServerAddress 

This also doesn't do anything, since I'm pretty sure I'm just updating a variable and not "committing" it.

So how can I update the server address? It doesn't even have to be PowerShell, that was just the best option I could find.

2 Answers 2

2

I ended up writing a .NET application using DotRas.

If anyone's interested, here's the code:

Public Const EntryName As String = "VPNEntryNAme"
Public Const NewAddress As String = "NewVPNAddress"

Private Sub B_Update_Click(sender As Object, e As EventArgs) Handles B_Update.Click
    Using pbk As New RasPhoneBook()
        pbk.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers))

        Dim VPN = pbk.Entries.Where(Function(Entry) Entry.Name = EntryName).FirstOrDefault

        If VPN Is Nothing Then
            MsgBox("VPN not found!", MsgBoxStyle.Critical)
            Exit Sub
        End If

        VPN.PhoneNumber = NewAddress

        VPN.Update()
    End Using

    Dim cn = RasConnection.GetActiveConnections.Where(Function(c) c.EntryName = EntryName).FirstOrDefault

    If cn IsNot Nothing Then
        cn.HangUp()
    End If

    MsgBox("The VPN has now been successfully updated")
End Sub
0

On my side, everything worked fine when I use

Set-VpnConnection -Name MyConnectionName -ServerAddress = "x.x.x.x"

Maybe you can try to remove the old one and a new one

$Connection = Get-VpnConnection -Name MyConnectionName

Remove-VpnConnection -Name MyConnectionName -Force

$Connection.ServerAddress = "x.x.x.x"

$Connection | Add-VpnConnection
2
  • I wasn't aware you could do $Connection | Add-VpnConnection, but, unfortunately, neither of these are working for me. Set-VpnConnection doesn't update the server address for me. $Connection | Add-VpnConnection does update the address, but it also loses some of the other settings, such as "PPP Settings" and the preferred and alternate DNS server addresses. Jun 14, 2020 at 20:50
  • How this vpn connection has originally been setup ? GPO, Intune,..
    – Mike
    Jun 14, 2020 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.