diff --git a/Scripts/check-vpn.ps1 b/Scripts/check-vpn.ps1 index 74abb055..17347226 100755 --- a/Scripts/check-vpn.ps1 +++ b/Scripts/check-vpn.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Checks the VPN connections .DESCRIPTION - This script checks all available VPN connections. + This script checks the status of all available VPN connections. .EXAMPLE PS> ./check-vpn .LINK @@ -12,17 +12,15 @@ #> try { + $FoundOne = $false $Connections = (Get-VPNConnection) - $Reply = "" foreach($Connection in $Connections) { - if ("$Reply" -eq "") { $Reply += "VPN connection " } else { $Reply += ", " } - $Reply += "$($Connection.Name) is $($Connection.ConnectionStatus)" + & "$PSScriptRoot/give-reply.ps1" "VPN $($Connection.Name) is $($Connection.ConnectionStatus)." + $FoundOne = $true } - if ("$Reply" -eq "") { $Reply = "No VPN connection available" } - - & "$PSScriptRoot/give-reply.ps1" "$Reply" - exit 0 # success + if (!$FoundOne) { throw "No VPN connection available" } + exit 0 } catch { - "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" + & "$PSScriptRoot/give-reply.ps1" "Sorry: $($Error[0])." exit 1 }