【问题标题】:Change ServerAddress of VPN connection更改 VPN 连接的 ServerAddress
【发布时间】:2020-10-04 04:27:50
【问题描述】:

我在 30 多台客户端计算机上配置了点到站点 VPN 连接,我只需要更改 VPN 网关的地址。当然,这意味着我必须重新配置所有客户端机器。我希望我可以创建某种可以运行的程序或脚本来自动更新内容,而不是手动进行。 唯一我需要更改的是服务器地址,其他一切都应该保持不变。

我遇到了这些 PowerShell 命令 Get-VpnConnectionSet-VpnConnection。我可以使用以下命令成功检索创建的 VPN 连接:

Get-VpnConnection MyConnectionName -AllUserConnection

所以我尝试使用Set 变体:

Set-VpnConnection -Name MyConnectionName -ServerAddress NewServerAddress -AllUserConnection

但这只是返回并且什么都不做。没有错误,没有效果。用rasphone查看服务器地址,发现旧地址仍在使用中。

我也可以这样做:

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

这也没有任何作用,因为我很确定我只是在更新一个变量而不是“提交”它。

那么如何更新服务器地址呢?它甚至不必是 PowerShell,这只是我能找到的最佳选择。

【问题讨论】:

    标签: windows powershell vpn


    【解决方案1】:

    我最终使用 DotRas 编写了一个 .NET 应用程序。

    如果有人感兴趣,这里是代码:

    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
    

    【讨论】:

      【解决方案2】:

      在我这边,我使用时一切正常

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

      也许您可以尝试删除旧的和新的

      $Connection = Get-VpnConnection -Name MyConnectionName
      
      Remove-VpnConnection -Name MyConnectionName -Force
      
      $Connection.ServerAddress = "x.x.x.x"
      
      $Connection | Add-VpnConnection
      

      【讨论】:

      • 我不知道你可以这样做$Connection | Add-VpnConnection,但不幸的是,这些都不适合我。 Set-VpnConnection 不会为我更新服务器地址。 $Connection | Add-VpnConnection确实更新了地址,但它也丢失了一些其他设置,例如“PPP 设置”以及首选和备用 DNS 服务器地址。
      • 这个 vpn 连接最初是如何设置的? GPO、Intune、..
      猜你喜欢
      • 2021-06-05
      • 2012-07-30
      • 2016-07-31
      • 1970-01-01
      • 2010-11-23
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多