Powershell 中的 VPN

Log*_*tte 2 vpn powershell automation pptp

我正在更新一个旧的 DOS 脚本,该脚本用于在两台服务器之间打开 Windows PPTP VPN 连接,复制一些文件,然后关闭连接。我想在 powershell 中重写脚本,因此如果副本出现任何问题,我将能够发送电子邮件通知用户。

当前代码如下

rasdial connectionName UserName Password
if not %errorlevel% == 0 goto vpn
Run Code Online (Sandbox Code Playgroud)

当我尝试在 powershell 中使用 rasdial 时,它会打开一个新窗口,而 powershell 无法访问 %errorlevel% 或 $lastexitcode。

有没有办法让 powershell 在同一个窗口中打开 rasdial?如果没有,是否有其他实用程序可用于打开 VPN 连接?

谢谢

Cal*_*res 6

这是您获得退出代码的方式:

(Start-Process rasdial -NoNewWindow -ArgumentList "connectionName UserName Password" -PassThru -Wait).ExitCode
Run Code Online (Sandbox Code Playgroud)