powershell - 设置用户名和密码 VPN powershell

标签 powershell

我有一个 powershell 脚本,可以在其中将 VPN 添加到本地计算机。它会提示用户输入凭据,然后创建 VPN 连接并添加凭据。当我在自己的计算机上尝试此操作时,它工作得很好,但当我在另一台计算机上尝试此操作时,它会给出错误,指出 Set-VpnConnectionUsernamePassword 不是命令。

有谁知道导致此问题的原因或如何解决此问题。

$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

最佳答案

错误消息表明在另一台计算机上,模块 VPNCredentialsHelper未安装。

除此之外,还有你的代码

$plainpassword = $creds.password

变量$plainpassword将接收密码作为System.Security.SecureString,但代码需要一个纯文本字符串(因此变量名称)。

您应该将其更改为

$plainpassword = $creds.GetNetworkCredential().Password

关于powershell - 设置用户名和密码 VPN powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60883934/

相关文章:

powershell - 连接/合并数组的属性

powershell - 从AD中随机选择用户

regex - 双/三行换行符时分割字符串

powershell - PowerShell-子字符串正则表达式

powershell - Try/Catch 或 Error 变量并使用

powershell - 如何在 PowerShell 中使用 Invoke-Build 创建动态构建任务

Powershell 命令在 Powershell 中有效,但在脚本中无效,为什么?

powershell - 当它们位于不同节点时,为什么 PowerShell DSC 说我有重复的资源标识符?

powershell - 如何通过 PowerShell Cmdlet 从 schtasks.exe 获取所有可用信息?

Powershell 调用程序集委托(delegate)