Connect-Vpn
Connects to the VPN
try {
$connections = (Get-VPNConnection)
foreach($connection in $connections) {
if ($connection.ConnectionStatus -eq "Connected") { throw "Already connected to VPN $($connection.Name)" }
if ($connection.ConnectionStatus -ne "Disconnected") { continue }
"? Connecting to $($Connection.Name)..."
& rasdial.exe "$($Connection.Name)"
if ($lastExitCode -ne 0) { throw "Cannot establish connection" }
"? VPN connected."
exit 0 # success
}
throw "No VPN connection available"
} catch {
"?? ERROR: $($Error[0])"
exit 1
}This script has no configurable parameters.