#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

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts