PowerShell Script to Check Windows Firewall Status

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.
### Step 1: Get the Firewall Profile
First, we need to retrieve the current configuration of the Windows Firewall profile. This will help us determine if the firewall is enabled or disabled.

$firewallProfiles = Get-NetFirewallProfile

### Step 2: Display Firewall Status
Next, we will loop through each firewall profile and display its status. This includes whether each profile is enabled and its associated rules.

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

### Step 3: Optional: Enable Firewall
If you find that any of the firewall profiles are disabled, you can enable them with an additional command. This step will ensure that the firewall is active, adding an extra layer of security to the system.

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

### Conclusion
This PowerShell script provides a simple and effective way to check and manage the state of the Windows Firewall. Ensuring that the firewall is enabled is a fundamental step in maintaining a secure operating environment. If you discover any disabled profiles, you have the option to enable them directly from the script.