Create a New Firewall Rule with PowerShell

This is a short post to share a PowerShell script that will create a new Windows Firewall Rule on a your computer. We have to ensure that we run PowerShell as Administrator for this to work.

# New firewall rule (run powershell as administrator)
if (-not( Get-NetFirewallRule -DisplayName “Allow Inbound SQL (1433)” -ErrorAction SilentlyContinue)) { 
New-NetFirewallRule `
    -DisplayName “Allow Inbound SQL - 1433” `
    -Direction Inbound `
    -Protocol TCP `
    -LocalPort 1433 `
    -Action Allow }
PowerShell New Firewall Rule

The above is creating a new firewall rule so inbound SQL Server (1433) traffic is allowed through on this computer.

For more information on managing the Windows Firewall, click the blog tag below!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *