← script library

PowerShell Script to Check Windows Firewall Status

Security & AuditingJanuary 12, 2025

In this post, we will create a PowerShell script that checks the status of the Windows Firewall on a local machine. This is important for security practices, ensuring that the firewall is enabled and configured properly to protect the system from unauthorized access.

powershell
$firewallProfiles = Get-NetFirewallProfile

foreach ($profile in $firewallProfiles) {
    $status = if ($profile.Enabled) { 'Enabled' } else { 'Disabled' }
    Write-Host "$($profile.Name) Firewall is: $status"
}

foreach ($profile in $firewallProfiles) {
    if (-not $profile.Enabled) {
        Enable-NetFirewallProfile -Name $profile.Name
        Write-Host "$($profile.Name) Firewall has been enabled."
    }
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.