Update check-vpn.ps1

This commit is contained in:
Markus Fleschutz 2021-12-07 12:07:23 +01:00
parent bbdac87cde
commit 3fa92d1935

View File

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