From bbdac87cde04ad0dd6ac91211654cf423872a439 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 7 Dec 2021 11:51:47 +0100 Subject: [PATCH] Add connect-vpn.ps1 --- Docs/VoiceControl.md | 1 + Scripts/connect-vpn.ps1 | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Scripts/connect-vpn.ps1 diff --git a/Docs/VoiceControl.md b/Docs/VoiceControl.md index 32f2e43a..34fe9ec9 100644 --- a/Docs/VoiceControl.md +++ b/Docs/VoiceControl.md @@ -102,6 +102,7 @@ Lets the computer check something, replace [name] by: `Bitcoin rate`, `Christmas * `Computer, tell joke` * `Computer, tell quote` * `Computer, repeat last reply` +* `Computer, connect VPN` 💬 Welcome & Farewell diff --git a/Scripts/connect-vpn.ps1 b/Scripts/connect-vpn.ps1 new file mode 100644 index 00000000..ab81a23a --- /dev/null +++ b/Scripts/connect-vpn.ps1 @@ -0,0 +1,29 @@ +<# +.SYNOPSIS + Connects to the VPN +.DESCRIPTION + This script tries to connect to the VPN. +.EXAMPLE + PS> ./connect-vpn +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz · License: CC0 +#> + +try { + $Connections = (Get-VPNConnection) + foreach($Connection in $Connections) { + if ($Connection.ConnectionStatus -eq "Disconnected") { + & "$PSScriptRoot/give-reply.ps1" "Connecting to VPN $($Connection.Name)..." + & rasdial.exe "$($Connection.Name)" + if ($lastExitCode -ne "0") { throw "Cannot establish connection" } + & "$PSScriptRoot/give-reply.ps1" "Connected now." + exit 0 # success + } elseif ($Connection.ConnectionStatus -eq "Connected") { throw "Already connected to VPN $($Connection.Name)" } + } + throw "No VPN connection available" +} catch { + & "$PSScriptRoot/give-reply.ps1" "Sorry: $($Error[0])" + exit 1 +}