PowerShell/Scripts/check-vpn.ps1

32 lines
667 B
PowerShell
Raw Normal View History

2021-12-02 14:49:17 +01:00
<#
.SYNOPSIS
2023-04-11 10:48:59 +02:00
Checks the VPN status
2021-12-02 14:49:17 +01:00
.DESCRIPTION
2023-04-11 10:48:59 +02:00
This PowerShell script queries the status of the VPN connections and prints it.
2021-12-02 14:49:17 +01:00
.EXAMPLE
PS> ./check-vpn
2023-04-17 21:38:20 +02:00
Disconnected VPN 'NASA L2TP'
2021-12-02 14:49:17 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
2021-12-02 14:49:17 +01:00
#>
try {
2022-10-25 14:58:55 +02:00
$NoVPN = $true
2022-10-11 20:00:39 +02:00
if ($IsLinux) {
# TODO
} else {
2023-01-01 19:22:35 +01:00
$Connections = Get-VPNConnection
2022-10-11 20:00:39 +02:00
foreach($Connection in $Connections) {
2023-04-17 21:38:20 +02:00
"$($Connection.ConnectionStatus) VPN '$($Connection.Name)'"
2022-10-25 14:58:55 +02:00
$NoVPN = $false
2022-10-11 20:00:39 +02:00
}
2021-12-02 14:49:17 +01:00
}
2023-04-17 21:38:20 +02:00
if ($NoVPN) { "⚠️ No VPN" }
2022-04-13 12:06:32 +02:00
exit 0 # success
2021-12-02 14:49:17 +01:00
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-12-02 14:49:17 +01:00
exit 1
2023-04-17 21:38:20 +02:00
}