#PowerShell Script Windows IKEv2 VPN vpn.student.ehb.be ################################ # VARIABLES $Name = "vpn.student.ehb.be" $ServerAddress = "vpn.student.ehb.be" $TunnelType = "IKEv2" $AuthenticationMethod = "EAP" $EncryptionLevel = "Maximum" $SplitTunneling = $true $DnsSuffix = "ehb.local" ################################ write-host -nonewline $Name" will be installed. Continue? (Y/N) " $response = read-host If(-not($response)){$response = "Y"} if ( $response -ne "Y") { exit } #Check if vpn.student.ehb.be is installed if ((Get-VpnConnection -Name $Name -ErrorAction SilentlyContinue) -Or (Get-VpnConnection -AllUserConnection -Name $Name -ErrorAction SilentlyContinue)) { Write-Host $Name" does already exist, remove if before running this script again" pause } # Else, create VPN connection else { #Disconnect VPN Get-VpnConnection -AllUserConnection | Where-Object {$_.ConnectionStatus -eq "Connected"} |Rasdial.exe /disconnect Get-VpnConnection | Where-Object {$_.ConnectionStatus -eq "Connected"} #Remove old VPN #Get-VpnConnection |Remove-VpnConnection -Force #Install IKEv2 VPN Add-VpnConnection -Name $Name -ServerAddress $ServerAddress -TunnelType $TunnelType -EncryptionLevel $EncryptionLevel -DnsSuffix $DnsSuffix -AuthenticationMethod $AuthenticationMethod -Force Set-VpnConnection -Name $Name -SplitTunneling $SplitTunneling -Force #Extra Routing VPN Write-Host "Configuring routing options (if you see errors here, you will need admin rights)" Add-VpnConnectionRoute -ConnectionName $Name -DestinationPrefix 10.0.0.0/8 -RouteMetric 2 Add-VpnConnectionRoute -ConnectionName $Name -DestinationPrefix 144.44.38.2/32 -RouteMetric 2 pause }