I would like to connect to a VPN using command line but I saw that the only way to connect is to have the connection saved, but I would like to do it without having connection saved like that:

C:\WINDOWS\system32> rasdial [IP or Hostname]

I don't believe it's possible to connect with a VPN profile that isn't saved, but you can create a connection on the command line with PowerShell, using the Add-VpnConnection cmdlet specifically.

For example, to create a VPN connection, you might do something like this:

Add-VpnConnection -Name 'MyNewVpn' -ServerAddress 'vpn.example.com'

Depending on your VPN server, you may need to provide more of the named parameters.

You can then connect to it with rasdial:

rasdial MyNewVpn myUsername mySuperSecretPassword

You can remove the VPN settings with PowerShell's Remove-VpnConnection:

Remove-VpnConnection 'MyNewVpn'
  • Thanks, accepted the answer. Is is possible to modify the VPN Profile? – Anis Rétro Jul 9 '16 at 15:23
  • @AnisRétro Yes, using the Set-VpnConnection cmdlet. For example, Set-VpnConnection 'MyNewVpn' -ServerAddress 'new.example.com' changes the address of the MyNewVpn profile to new.example.com. – Ben N Jul 9 '16 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.