#PSTip Adding Firewall rules in Windows 8 and Server 2012

Note: This tip requires PowerShell 3.0 or above.

Before the release of Windows Server 2012 and Windows 8, adding rules to Windows Firewall required a painful approach of using the firewall COM object.

In Windows Server 2012 and Windows 8 operating systems, there is a new cmdlet called New-NetFirewallRule. This cmdlet provides a way to add new firewall rules.

The following example shows how to use this cmdlet to enable inbound traffic to port 80 on the local system.

New-NetFirewallRule -DisplayName "Allow Port 80" -Direction Inbound -LocalPort 80 -Protocol TCP
-Action Allow
Filed in: Columns, Tips and Tricks Tags: , , ,

5 Responses to "#PSTip Adding Firewall rules in Windows 8 and Server 2012"

  1. This is so very helpful…had a boring time enabling them via wf.msc…

  2. punk says:

    netsh advfirewall firewall add rule name=”Example” dir=out action=block program=”C:exampleexample.exe” “run this as admin as a .Bat file and your good to go also….to chang outbound or in-bound just chang Dir… OK….. peace punk

  3. JZ says:

    On Windows 2012 server, I have to add “-Protocol TCP” to your command.

Leave a Reply

Submit Comment

© 2018 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: