#PSTip Set Windows Firewall status in Windows Server 2012 and Windows 8

Note: This tip requires PowerShell 3.0 or above.

The NetSecurity module in Windows Server 2012 and Windows 8 lets us configure Windows Firewall settings locally and remotely. The _Set-NetFirewallProfile _can be used to enable or disable the firewall.

First, let us see how we can enable firewall

Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled True

To disable firewall, we can run

Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled False

The above commands will change the firewall status on the local computer. How about remote systems? Simple, we use the -CimSession parameter.

Get-NetFirewallProfile -CimSession Server-01 | Set-NetFirewallProfile -Enabled False

By default, the Get-NetFirewallProfile cmdlet returns all Firewall profiles — Domain, Private, and Public. So, by sending the output of this to Set-NetFirewallProfile, we can either disable or enable all profiles at once. It is also possible to select a specified profile using the -Name parameter.

Share on: