# PowerShell script to open required ports for SQL Server in Windows Firewall
# Define the list of SQL Server ports (modify as needed)
$ports = @(1433, 1434, 4022, 135, 2383, 2382, 135, 5985, 5986)
# Loop through each port and create an inbound rule
foreach ($port in $ports) {
$ruleName = "SQL Server Port $port"
$command = "netsh advfirewall firewall add rule name=`"$ruleName`" dir=in action=allow protocol=TCP localport=$port"
Invoke-Expression $command
Write-Host "Added inbound rule for port $port"
}
Write-Host "All required SQL Server ports have been opened in Windows Firewall."
You will also want to open port 8080 for health links on the best practice server to do that..
$ruleName = "MyApp-Port8080"
$port = 8080
# Create a new inbound rule to allow traffic on port 8080
New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Protocol TCP -LocalPort $port -Action Allow
# Print a success message
Write-Host "Port $port is now open."