-
Notifications
You must be signed in to change notification settings - Fork 0
/
L2TP.ps1
68 lines (59 loc) · 2.56 KB
/
L2TP.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# VPN Connection ‘L2TP’ provisioning
#------------------------------------------------------------
#Get Params from the Switchboard action like VirtualIP
param (
[string]$server = ""
)
#------------------------------------------------------------
# VPN Connection look-up to check any previous installations
$isTestVpn = $false
#Get all VPN Connection for the local user instead of AllUserConnection
#$vpnConnections = Get-VpnConnection -AllUserConnection
$vpnConnections = Get-VpnConnection
if($vpnConnections.Name -eq "L2TP")
{
try{
Write-Host "'L2TP' connection is already configured on your system." -ForegroundColor Yellow -BackgroundColor DarkGreen
try{
Write-Host "I'll update the L2TP ServerAddress, please wait..." -ForegroundColor Black -BackgroundColor Yellow
Write-Host ""
Set-VpnConnection -Name "L2TP" -ServerAddress $server -L2tpPsk "MyPre-Sharedkey" -TunnelType "L2TP" -RememberCredential $True -EncryptionLevel Optional -AuthenticationMethod Pap -Force
}
catch{
Write-Host "Error during the connection" -ForegroundColor White -BackgroundColor Red
Write-Host $_.Exception.Message
throw
}
Write-Host "We try now to start the VPN Connection" -ForegroundColor Yellow -BackgroundColor DarkGreen
Write-Host ""
rasdial L2TP MyUsername MyPassword
exit
}
catch{
Write-Host "Error during the connection" -ForegroundColor White -BackgroundColor Red
Write-Host $_.Exception.Message
throw
}
}
Write-Host "******************************************" -ForegroundColor Black -BackgroundColor White
Write-Host " Installing 'L2TP’ connection " -ForegroundColor Black -BackgroundColor White
Write-Host "__________________________________________" -ForegroundColor Black -BackgroundColor White
try
{
# Create the VPN connection
#Add-VpnConnection -Name "L2TP" -ServerAddress "contoso.com" -L2tpPsk ""MyPre-Sharedkey"" -TunnelType "L2TP" -RememberCredential $True -EncryptionLevel Optional -AuthenticationMethod Pap
Add-VpnConnection -Name "EL2TP" -ServerAddress $server -L2tpPsk ""MyPre-Sharedkey"" -TunnelType "L2TP" -RememberCredential $True -EncryptionLevel Optional -AuthenticationMethod Pap -Force
}
catch
{
Write-Host "Error in connection setup!" -ForegroundColor White -BackgroundColor Red
Write-Host $_.Exception.Message
throw
}
Write-Host ""
Write-Host "‘L2TP’ VPN connection is ready for use." -ForegroundColor Black -BackgroundColor White
Write-Host ""
Write-Host "We try now to start the VPN Connection" -ForegroundColor Yellow -BackgroundColor DarkGreen
Write-Host ""
rasdial L2TP MyUsername MyPassword
exit