Reputation: 37
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
Upvotes: 2
Views: 5067
Reputation: 61068
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
Upvotes: 2