我在30台以上的客户端计算机上配置了点到站点VPN连接,而我只需要更改VPN网关的地址。当然,这意味着我必须重新配置所有客户端计算机。我希望能够创建一些可以自动更新的程序或脚本,而不是手动进行操作。我需要更改的唯一内容是服务器地址,其他所有内容都应保持不变。
我遇到了这些PowerShell命令Get-VpnConnection和Set-VpnConnection。我可以使用以下命令成功恢复创建的VPN连接:
Get-VpnConnection MyConnectionName -AllUserConnection
所以我尝试使用Set
变体:
Set-VpnConnection -Name MyConnectionName -ServerAddress NewServerAddress -AllUserConnection
但这只是返回而无所作为。没有错误,没有影响。用rasphone检查服务器地址显示旧地址仍在使用。
我也可以这样做:
$connection = Get-VpnConnection MyConnectionName -AllUserConnection
$connection.ServerName = NewServerAddress
这也不做任何事情,因为我敢肯定我只是在更新变量而不是“提交”它。
那么我该如何更新服务器地址?甚至不必是PowerShell,那只是我能找到的最佳选择。
答案 0 :(得分: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
答案 1 :(得分:0)
在我这边,使用
时一切正常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