PowerShell/Scripts/check-vpn.ps1
2023-07-01 16:40:40 +02:00

32 lines
672 B
PowerShell
Executable File

<#
.SYNOPSIS
Checks the VPN status
.DESCRIPTION
This PowerShell script queries the status of the VPN connection(s) and prints it.
.EXAMPLE
PS> ./check-vpn
✅ VPN to NASA L2TP: Disconnected
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$NoVPN = $true
if ($IsLinux) {
# TODO
} else {
$Connections = Get-VPNConnection
foreach($Connection in $Connections) {
"✅ VPN to $($Connection.Name): $($Connection.ConnectionStatus)"
$NoVPN = $false
}
}
if ($NoVPN) { "⚠️ No VPN" }
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}