Creating a VPN connection with RMM

Now that everyone is working from home, you might find yourself needing to rapidly setup VPN connections on a ton of machines at once. Rather than connecting to every users computer to setup the VPN, or relying on users to follow a guide to setup the VPN themselves and figuring out a way to share the Shared Secret with them, you can easily deploy VPN connections through your RMM:

function Add-L2TPVpnConnection {
  param(
    [string]$Name,
    [string]$ServerAddress,
    [string]$Psk,
    [string]$DnsSuffix
  )
  # Don't try to recreate the same VPN again.
  if (Get-VPNConnection $Name -ErrorAction SilentlyContinue) {
    Write-Error "VPN Connection already exists"
    return $true
  }
  
  Add-VpnConnection -Name $Name -ServerAddress $ServerAddress -TunnelType L2tp -L2tpPsk $Psk -EncryptionLevel Required -AuthenticationMethod MSChapv2 -RememberCredential -AllUserConnection -DnsSuffix $DNSSuffix -Force
}

Add-L2TPVpnConnection -Name "{[ConnectionName]}" -ServerAddress "{[ServerAddress]}" -Psk "{[PreSharedKey]}" -DnsSuffix "{[DNSSuffix]}"

The script will take in variables set through your RMM platform (I've setup the script for Atera), so you just have to change the last line to pass in variables however your RMM platform of choice handles them.