1

I can easily create a VPN connection through the PowerShell command Add-VpnConnection, however it doesn't seem able to specify any credentials (there is no option to specify username/password). As a workaround I tried to use -RememberCredential option in Add-VpnConnection and to pass the credentials by forcing a connection through rasdial command, yet even though the connection succeeds Windows doesn't save the credentials :(

Add-VpnConnection -Name xxxxx ...
rasdial xxxxx user password
rasdial xxxxx /disconnect

Is it possible some way ?

Matt
  • 45,022
  • 8
  • 78
  • 119
fededim
  • 429
  • 5
  • 12
  • If you do the connection manually (no PS) does Remember Credentials work? (related [question on SuperUser](http://superuser.com/questions/521348/how-to-connect-with-a-vpn-connection-without-any-prompt-in-windows-8)) – Χpẘ Feb 17 '16 at 02:00
  • you should probably google a bit for the answer and post what you've googled and why they don't apply, if they don't apply. I've seen several related questions on SuperUser. – Χpẘ Feb 17 '16 at 02:05
  • @Xpw yes to both your comments, but noone has not ever given an answer :) I have however solved using the dotras dll (see http://web2.codeproject.com/Articles/1158881/VPNScripter-a-scripter-for-Windows-VPN-connections) . Probably credentials can configured by specifying a particular xml configuration file in the EapConfigXmlStream field, but I was unable to find how to do it, if someone knows please let me know. – fededim Mar 22 '17 at 17:30

1 Answers1

0

Maybe it is too late, but I had same task and here is solution:

$vpnName = "YourVpnName"
$vpnServerAddress = "YourVpnServerAddress"
$vpnUserName = "YourVpnUserName"
$vpnPassword = "YourVpnPassword"
$vpn = Get-VpnConnection -Name $vpnName
if($vpn -eq $null) {
    Add-VpnConnection -Name $vpnName -ServerAddress $vpnServerAddress -TunnelType Pptp -EncryptionLevel Required -PassThru
    echo "vpn created"
}

if($vpn.ConnectionStatus -eq "Disconnected"){
        $cmd = $env:WINDIR + "\System32\rasdial.exe"
        $expression = "$cmd ""$vpnName"" $vpnUserName $vpnPassword"
        Invoke-Expression -Command $expression 
}
user1893999
  • 255
  • 1
  • 3
  • 6
  • Tried the answer but get: Remote Access error 703 - The connection needs information from you, but the application does not allow user interaction. – wdtj Apr 29 '19 at 15:34
  • I tried your solution. But it is not save credentials. – FiftiN Mar 29 '20 at 22:40