This repository contains the code used to build the PowerShell helper module: VPNCredentialsHelper.
The module can set a username, password and presharedkey directly for a named VPN connection, so that you are not prompted to enter it the first time you connect.
To install the module enter the following PowerShell command.
Install-Module -Name VPNCredentialsHelper
This will add the Set-VpnConnectionCredential as a PowerShell command.
And then you can script something like this:
$name = "ExpressVPN Australia Sydney"
$address = "aus1-ubuntu-l2tp.expressprovider.com"
$username = "your_username"
$plainpassword = "your_password"
Add-VpnConnection -Name $name -ServerAddress $address -TunnelType L2tp -EncryptionLevel Required -AuthenticationMethod MSChapv2 -L2tpPsk "12345678" -Force:$true -RememberCredential:$true -SplitTunneling:$false
Set-VpnConnectionCredential -ConnectionName $name -UserName $username -Password $plainpassword -Domain ''
# or
$Cred = Get-Credential
$PSK = Get-Credential
Set-VpnConnectionCredential -ConnectionName $name -Credential $Cred -PreSharedKey $PSK
Please note: you will have to set your policy to permit unsigned PowerShell scripts to execute, to run this command.
If you're nervous about doing this, the actual script source code can be found here.
A huge thanks to Jeff Winn for the DotRas project (https://dotras.codeplex.com/) which showed me the way, and who did all the really hard work.
This module differs from the original module in the following changes:
- Added support for L2TP PreShared Key
- Cmdlet renamed to
Set-VpnConnectionCredential
to be more powershell style - Added support for
PSCredential
object as credential source - Implemented pipeline support for connections/credentials
- Added help