Back to Resources
Level
Script
Security
Many organizations struggle to ensure that Windows Firewall remains consistently active across all network profiles, leaving devices vulnerable to threats. This script resolves the issue by quickly detecting whether any firewall profile is enabled, so administrators can immediately address potential security gaps.
The script examines the status of each Windows Firewall profile—domain, private, and public. If it finds even one profile with its firewall enabled, it returns a success message and a zero exit code; otherwise, it delivers an alert and exits with a non-zero code, triggering any follow-up actions within Level. By scanning multiple profiles, it provides a comprehensive firewall assessment without additional manual checks.
1<#
2This resource is provided as a convenience for Level users. We cannot
3guarantee it will work in all environments. Please test before deploying
4to your production environment. We welcome contributions to our community
5library
6
7Level Library
8https://level.io/library/script-windows-check-firewall
9#>
10
11# Initialize a variable to track if any firewall profile is active
12$firewallActive = $false
13
14# Function to check the status of Windows Firewall for all profiles
15function Check-FirewallStatus {
16 $profiles = Get-NetFirewallProfile
17 foreach ($profile in $profiles) {
18 $status = $profile.Enabled
19 $name = $profile.Name
20 if ($status -eq "True") {
21 Write-Host "$name profile firewall is ENABLED."
22 $global:firewallActive = $true
23 }
24 else {
25 Write-Host "$name profile firewall is DISABLED."
26 }
27 }
28}
29
30# Check firewall status for all profiles
31Check-FirewallStatus
32
33# Determine script exit code based on firewall status
34if ($firewallActive) {
35 Write-Host "SUCCESS: At least one firewall profile is active."
36 exit 0
37}
38else {
39 Write-Host "ALERT: No active firewall profiles detected."
40 exit 1
41}
42
Windows - Check Firewall
This script checks the status of Windows Firewall for all profiles (Domain, Private, and Public) using the Get-NetFirewallProfile cmdlet. It outputs the status of each profile, sets a global variable if any profile is active, and exits with a success or alert code based on whether at least one firewall profile is enabled.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.