我在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,那只是我能找到的最佳选择。
我最终使用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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句