Skip to main content

Basic Windows L2TP VPN Worklet

  • November 17, 2020
  • 4 replies
  • 69 views

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

Change the values: vpnName, serverAddress, yourPsk, authMethod

Evaluation Code:

Get-VpnConnection -Name "vpnName"

Remediation Code:

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

4 replies

bfrey
  • Power User
  • 23 replies
  • November 25, 2020

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


NickCo
Forum|alt.badge.img
  • Former Automox Employee
  • 6 replies
  • November 25, 2020

Hey @bfrey!

Try the following:

    #############################################
    # 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:

#############################################
# 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
}

bfrey
  • Power User
  • 23 replies
  • November 25, 2020

Thank you for helping with this one!


NickCo
Forum|alt.badge.img
  • Former Automox Employee
  • 6 replies
  • November 25, 2020

No problem!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings