Automate Windows Firewall Configuration with PowerShell
In this post, we will showcase a PowerShell script that automates the configuration of the Windows Firewall on your system. Proper firewall configuration is essential for maintaining security and preventing unauthorized access to your network. This script allows administrators to swiftly enable or disable firewall rules, customize settings, and ensure that the appropriate ports are open for necessary applications, enhancing both security and functionality. Here is the PowerShell script for managing Windows Firewall rules:
# Define variables for the firewall configuration
$ruleName = "Allow Web Traffic"
$portNumber = 80
# Enable Windows Firewall
Set-NetFirewallProfile -Enabled True
# Create a new inbound firewall rule to allow web traffic
New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Protocol TCP -LocalPort $portNumber -Action Allow
# Check if the rule was created successfully
Get-NetFirewallRule -DisplayName $ruleName | Format-List
Write-Host "Firewall rule '$ruleName' for port $portNumber created successfully."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.
More in Security & Auditing
Enable the Windows Firewall with PowerShell
2026-08-17Check Windows Firewall Status with PowerShell
2026-08-17Disable SMBv1 with PowerShell
2026-08-17Enforce TLS 1.2 in the Registry with PowerShell
2026-08-17Enable RDP Network Level Authentication with PowerShell
2026-08-17Audit the Local Administrators Group with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.