Skip to content

Configure SQL firewall rules

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# SQL Firewall Rules
Invoke-Command -ComputerName $ServerName -ScriptBlock {
  If ((Get-NetFirewallRule -DisplayName 'SQL Traffic*') -eq $null)
  {
    Write-Verbose -Message "Writing SQL Firewall Rules for $ServerName"
    New-NetFirewallRule -DisplayName 'SQL Traffic - Port (TCP)' -Enabled True -Direction Inbound -Action Allow -LocalPort 1433 -Protocol TCP -Profile Domain
    New-NetFirewallRule -DisplayName 'SQL Traffic - Browser (TCP)' -Enabled True -Direction Inbound -Action Allow -LocalPort 1434 -Protocol TCP -Profile Domain
    New-NetFirewallRule -DisplayName 'SQL Traffic - Service Broker (TCP)' -Enabled True -Direction Inbound -Action Allow -LocalPort 4022 -Protocol TCP -Profile Domain
  }
  Else
  {
    Write-Verbose -Message "SQL Firewall Rules exist on $ServerName. Continuing..."
  }
}