问题
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