PowerShell/Scripts/check-firewall.ps1

33 lines
708 B
PowerShell
Raw Normal View History

2023-01-06 21:55:52 +01:00
<#
.SYNOPSIS
Check the firewall
.DESCRIPTION
This PowerShell script queries and prints firewall details.
.EXAMPLE
PS> ./check-firewall
2023-01-12 20:45:19 +01:00
Firewall enabled
2023-01-06 21:55:52 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
if ($IsLinux) {
2023-01-12 20:45:19 +01:00
Write-Host "✅ Firewall " -noNewline
& sudo ufw status
2023-01-06 21:55:52 +01:00
} else {
$enabled = (gp 'HKLM:\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile').EnableFirewall
if ($enabled) {
Write-Host "✅ Firewall enabled"
} else {
Write-Host "⚠️ Firewall disabled"
}
}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2023-01-12 20:45:19 +01:00
}