#PSTip Get Windows Firewall rule status in Windows 8 and Server 2012
Note: This tip requires PowerShell 3.0 or above.
In an earlier tip, we looked at how we can add firewall rules in Windows 8 or Windows Server 2012. In today’s tip, we shall look at how we can get the firewall rules from local and remote systems in Windows 8 and Windows Server 2012 systems.
We can use the Get-NetFirewallRule cmdlet to achieve this. First, let us see how we can use this cmdlet on the local system.
Get-NetFirewallRule -All
The above command will list all available Firewall rules irrespective of their state (enabled or disabled) or action (allowed or denied). To filter this further to only enabled firewall rules, we can run:
Get-NetFirewallRule -Enabled True
We can filter this further and retrieve only the rules that are enabled and are set to allow.
Get-NetFirewallRule -Enabled True -Action Allow
So, how do we use this to retrieve the rules from a remote system? Simple, we need to use a computer name string or a CIM session object as an argument to the -CimSession parameter of Get-NetFirewallRule cmdlet.
$cimSession = New-CimSession -ComputerName Server-03 Get-NetFirewallRule -CimSession $cimSession -Enabled True -Action Allow
Or
Get-NetFirewallRule -CimSession Server-03 -Enabled True -Action AllowShare on: