PowerShell/scripts/check-vpn.ps1

32 lines
720 B
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
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-08-21 22:06:58 +02:00
This PowerShell script queries the status of the VPN connection(s) and prints it.
2021-12-02 14:49:17 +01:00
.EXAMPLE
2023-07-17 11:25:30 +02:00
PS> ./check-vpn.ps1
2023-09-13 08:34:59 +02:00
VPN to NASA L2TP is connected
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 {
2023-08-21 22:06:58 +02:00
$noVPN = $true
2022-10-11 20:00:39 +02:00
if ($IsLinux) {
# TODO
} else {
2024-05-17 19:31:10 +02:00
$connections = Get-VPNConnection
foreach($connection in $connections) {
Write-Host "✅ VPN to $($connection.Name) is $($connection.ConnectionStatus.ToLower())"
2023-08-21 22:06:58 +02:00
$noVPN = $false
2022-10-11 20:00:39 +02:00
}
2021-12-02 14:49:17 +01:00
}
2023-08-21 22:06:58 +02:00
if ($noVPN) { Write-Host "⚠️ No VPN configured" }
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
}