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
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
}