Connect to VPN by Powershell

冷暖自知 提交于 2020-01-21 06:13:07

问题


I'd like my Windows to connect to the VPN server as soon as it loads. How can I do it using Powershell?


回答1:


Try this works with windows 10

    $vpnName = "YOUR_VPN_NAME";
    $vpn = Get-VpnConnection -Name $vpnName;
    if($vpn.ConnectionStatus -eq "Disconnected"){
    rasdial $vpnName;
    }



回答2:


You could try something like this:

I have not tested if it works. I have PowerShell V3 Beta installed - it may be necessary to run these commands.

Register-ScheduledJob -name ConnectVPN -ScriptBlock { & rasphone MyVpnConnection 
$trigger = New-JobTrigger -AtLogOn
Add-JobTrigger -Name ConnectVPN -Trigger $trigger
Get-ScheduledJob -Name ConnectVPN | Get-JobTrigger



回答3:


Apart from the other answers, Windows 10 also natively supports this via a configuration called Always On. More details about always on are available at https://docs.microsoft.com/en-us/windows/access-protection/vpn/vpn-auto-trigger-profile

You can deploy either via a MDM or even using WMI/Powershell

References for Deployment

VPN 2 CSP: https://docs.microsoft.com/en-us/windows/client-management/mdm/vpnv2-csp

CSP to WMI Bridge : https://docs.microsoft.com/en-us/windows/client-management/mdm/using-powershell-scripting-with-the-wmi-bridge-provider



来源:https://stackoverflow.com/questions/10619285/connect-to-vpn-by-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!