Using PowerShell to create a VPN connection on a Windows 10 is quite easy. I used this command to create a VPN connection to a Meraki router.
$ServerAddress = "x.x.x.x" $ConnectionName = "XXX" $PresharedKey = "XXX" Add-VpnConnection -Name "$ConnectionName" -ServerAddress "$ServerAddress" -RememberCredential -TunnelType L2tp -AllUserConnection -L2tpPsk "$PresharedKey" -AuthenticationMethod Pap -Force
But what about if you want to add the clients VPN IP adress in your DNS?
Default “Register this connection’s addresses in DNS” for a VPN connection is not enabled and it is not possible to enable with the Add-VpnConnection PowerShell command.
Off course you can set it manually but if you want to do it automatically and deploy the setting you have to edit the Remote Access Phonebook with PowerShell
If it is a -alluserconnection the phonebook can be found here: “C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk”
If it is a per user connection the phonebook can be found here: “C:\Users\USERNAME\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk”
Use this Powershell command to set the setting:
$RASPhoneBook = "C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk" (Get-Content $RASPhoneBook) -Replace 'IpDnsFlags=0', 'IpDnsFlags=3' | Set-Content $RASPhoneBook