Adding credentials to VPN connection

Hi,

I am trying to deploy a VPN connection to all our users via Powershell, and am able to deploy the connection, but cannot add any credentials to it. I have been searching over the internet and reddit, but cant seem to find a solution to it.

I currently have this, which adds the connection - the credentials.

Add-VpnConnection -Name “test” -ServerAddress $vpnServerAddress -TunnelType L2tp -L2tpPsk $PSKEYTEST -RememberCredential

I also tried adding the credentials in parameters like so:

$vpnName = “test”

$vpnServerAddress = “server.address”

$vpnUserName = “username”

$vpnPassword = “password”

Add-VpnConnection -Name “test” -ServerAddress $vpnServerAddress -TunnelType L2tp -L2tpPsk $PSKEYTEST -RememberCredential -user $vpnUserName -password $vpnPassword

This return a parameter not found for ‘user’ . Removing everything from -user to the end of the script makes the script work, but doesn’t add credentials.

Anyone able to help me towards a solution? Thanks in advance for any help.

What do you mean add credentials, are you saying everything uses the same creds for the vpn

Cause you know that’s not a good idea, ever

but that aside why dont you start with

get-help -full Add-VpnConnection

this shows you all the parameters for the cmdlet -user is not 1

Add-VpnConnection does not have parameters for -user and -password
https://learn.microsoft.com/en-us/powershell/module/vpnclient/add-vpnconnection?view=windowsserver2022-ps

You can’t just make up your own parameters on the fly like that. :slight_smile:

Additionally, cred management isn’t included with the VpnClient module outside -RememberCredential & -UseWinLogonCredential but here’s a link to some people discussing how to get around it, might be what you need.
https://stackoverflow.com/questions/35442724/scripting-vpn-credentials

Users should be typing their own credentials. Your question implies that either you know everyone’s password, or the VPN uses the same user/pass for everyone. In both cases, something is horribly wrong and you should not proceed without taking a step back and considering your approach.

thanks for the info. The VPN connection we are trying to use is externally managed. These are the details we have received. I will contact them to see if this is solvable.

Oh and looking at how they’re doing it I’d be remiss if I didn’t say putting passwords in plain text like that is a pox on both our houses.
Might wanna use a vault or something…
https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/how-to/manage-secretstore?view=ps-modules

I mean chat gpt does, why can’t we /s

Thanks, as mentioned in a different reply, this VPN connection is provided by an external company. I will contact them to see if this can be changed.