set username and password VPN powershell

Viewed 2638

I have a powershell script where I can add an VPN to the local computer. It prompts for the users credentials and after that it creates the VPN connection and adds the credentials. When I try this on my own computer it works perfectly fine but when I try this on another computer it gives an error saying Set-VpnConnectionUsernamePassword isn't a command.

Does anyone know what causes this or how to fix this.

$creds = $host.ui.PromptForCredential("Need credentials", "Voer de inloggegevens in van de VPN gebruiker", "", "")
    $name = "name of vpn"
    $username = $creds.username
    $plainpassword = $creds.password
    Add-VpnConnection -Name $name -ServerAddress $name -RememberCredential -TunnelType Pptp
    Set-VpnConnectionUsernamePassword -connectionname $name -username $username -password $plainpassword
1 Answers

The error message indicates that on the other computer, the module VPNCredentialsHelper is not installed.

Beside that, with your code

$plainpassword = $creds.password

the variable $plainpassword will receive the password as System.Security.SecureString, but the code wants a plain-text string (hence the variable name).

You should change that to

$plainpassword = $creds.GetNetworkCredential().Password
Related