AutomoxAutomox

Basic Windows L2TP VPN Worklet

Reuben_F
November 17, 2020 at 1:48 pm UTC

This is a very basic method of setting up an L2TP VPN using a worklet.

Change the values: vpnName, serverAddress, yourPsk, authMethod

Evaluation Code:

1 line
Get-VpnConnection -Name "vpnName"

Remediation Code:

1 line
Add-VpnConnection -AllUserConnection -Name "vpnName" -ServerAddress "serverAddress" -TunnelType L2tp -EncryptionLevel Optional -L2tpPsk "yourPsk" -AuthenticationMethod authMethod -Force

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (4)

bfreyNovember 25, 2020
#1

What needs added to the Evaluation Code so that the worklet doesn’t run if there is already a VPN connection?

NickCoNovember 25, 2020
#2

Hey @bfrey!

Try the following:

powershell17 lines
    #############################################
    # VPN Connection - Evaluation
    $vpnName = "vpnName"
    #############################################

    try {
        # Check for connection existence
        if(-not(Get-VpnConnection -allUserConnection|Where-Object -Property Name -eq $vpnName)){
            exit 1
        } else {
            exit 0
        }
    }
    catch [Exception]{
        write-output "$_.Exception.Message"
        exit 1
    }

and remediation:

powershell38 lines
#############################################
# VPN Connection - Remediation
$vpnName              = "vpnName"
$serverAddress        = "x.x.x.x"
$tunnelType           = "L2tp"
$encryptionLevel      = "Optional"
$L2tpPsk              = "yourPsk"
$AuthenticationMethod = "authMethod"
#############################################

try {
    #                  Params               Variables
    Add-VpnConnection -AllUserConnection                          `
                      -Name                 $vpnName              `
                      -ServerAddress        $serverAddress        `
                      -TunnelType           $tunnelType           `
                      -EncryptionLevel      $encryptionLevel      `
                      -L2tpPsk              $L2tpPsk              `
                      -AuthenticationMethod $AuthenticationMethod `
                      -Force
}
catch [Exception]{
  write-output "$_.Exception.Message"
  exit 1
}

try {
    # Check for connection existence
    if(-not(Get-VpnConnection -allUserConnection|Where-Object -Property Name -eq $vpnName)){
        exit 1
    } else {
        exit 0
    }
}
catch [Exception]{
    write-output "$_.Exception.Message"
    exit 1
}
bfreyNovember 25, 2020
#3

Thank you for helping with this one!

NickCoNovember 25, 2020
#4

No problem!