I had to deploy a VPN connection in an environment which looks like this:
- Domain Controller is hosted on a Virtual Machine in Azure
- Using an Azure Virtual Network Gateway
- Point-to-site configuration uses RADIUS authentication.
I accomplished this using the Windows administrator’s best friend, PowerShell.
The prerequisites for these are:
- Get the VPN server IP/DNS
- Make sure computers are using PowerShell 3.0
The Powershell script to deploy a VPN connection would look like this:
#Set Variables for the VPN connection
$VPNconnectionName = "New VPN"
$SRVaddress = "auzrevpn.azure.com"
$dnssuf = "contoso.com"
#Create the VPN connection
Add-VpnConnection -Name $VPNconnectionName -ServerAddress $SRVaddress -TunnelType Sstp -AuthenticationMethod Eap -EncryptionLevel Required -AllUserConnection -SplitTunneling -IdleDisconnectSeconds 900 -DnsSuffix $dnssuf
#Get the content from the phone book
$contain = Get-Content -Path "$env:ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk" -Raw
#Change the connection phone book content to add the internal DNS entries
if ($contain.Contains("IpDnsAddress=0.0.0.0")){
($contain) -replace 'IpDnsAddress=0.0.0.0','IpDnsAddress=192.168.1.4' -replace 'IpDns2Address=0.0.0.0','IpDns2Address=192.168.1.10'-replace 'IpNameAssign=1','IpNameAssign=2'| Set-Content "$env:ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk"
}