May 1, 2013
Tags: database, ip-address, microsoft-sql-server, sql, transmission-control-protocol, windows-firewall
PowerShell Script for SQL Firewall rules
As Netsh Firewall commands are now deprecated , I have written a PowerShell script for use with deploying SQL or accessing remote instances.
Latest Version:
# Set the PowerShell execution policy to allow scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
# Enabling SQL Server Ports
New-NetFirewallRule -DisplayName "SQL Server - TCP 1433" -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow
New-NetFirewallRule -DisplayName "SQL Admin Connection - TCP 1434" -Direction Inbound -Protocol TCP -LocalPort 1434 -Action Allow
New-NetFirewallRule -DisplayName "SQL Database Management - UDP 1434" -Direction Inbound -Protocol UDP -LocalPort 1434 -Action Allow
New-NetFirewallRule -DisplayName "SQL Service Broker - TCP 4022" -Direction Inbound -Protocol TCP -LocalPort 4022 -Action Allow
New-NetFirewallRule -DisplayName "SQL Debugger/RPC - TCP 135" -Direction Inbound -Protocol TCP -LocalPort 135 -Action Allow
# Enabling SQL Analysis Services Ports
New-NetFirewallRule -DisplayName "SQL Analysis Services - TCP 2383" -Direction Inbound -Protocol TCP -LocalPort 2383 -Action Allow
New-NetFirewallRule -DisplayName "SQL Browser - TCP 2382" -Direction Inbound -Protocol TCP -LocalPort 2382 -Action Allow
# Enabling Miscellaneous Applications
New-NetFirewallRule -DisplayName "HTTP - TCP 80" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
New-NetFirewallRule -DisplayName "SSL - TCP 443" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
# Enable Windows Firewall with specific settings
Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow -NotifyOnListen True -AllowUnicastResponseToMulticast True