ПОШ-скрипт:
<#
.SYNOPSIS
This script adding L2TP over IPsec VPN.
.DESCRIPTION
With this Powershell Script, the addition of an L2TP over IPsec VPN can be automated.
.NOTES
Created by : T13nn3s
Version : 1.0.3 (11 December 2017)
#>
# Checks if powershell is in Administrator mode, if not powershell will fix it
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
# General settings
$VpnName = "MEGI"
$server = "IP-адрес сервера"
#write-host "$vpnname " -f yellow -NoNewline ; write-host "is the name of the connection and server" -NoNewline ; write-host " $server." -f Yellow
$psk = "PSK ключ"
#$regp = 'HKLM:\SYSTEM\CurrentControlSet\Services\PolicyAgent' # If VPN server is behind NAT, otherwise comment out this line.
# Add L2TP VPN
try {
Add-VpnConnection -Name $VpnName -ServerAddress $server -TunnelType L2tp -AuthenticationMethod MSChapv2 -EncryptionLevel Maximum -L2tpPsk $psk -RememberCredential -UseWinLogonCredential $false -SplitTunneling -Force
Write-Host "Connection has been added." -f Green
}
Catch {
$error.clear()
$ErrorMessage = $_.exception.Message
Write-Error "ERROR: $errormessage"
}
Add-VpnConnectionRoute -ConnectionName "MEGI" -DestinationPrefix "
192.168.112.39/32" -PassThru
ncpa.cpl