29/03/2024

Adding Windows Firewall Rules to a Group

Anyone who has used windows firewall, knows it is easier to create rules and configure, but hard to organize.

Though Windows Advanced Firewall interface shows a Group column, there is no easy way to set the group through UI.

In a recent task assigned to me, I wanted to organize my rules to several groups, that's when Powershell came in handy.

Let's say I have 5 rules I need to group. Currently they don't have a group.


I want to assign Rule 1, 2 and 3 to "My Group 1" and rule 4 and 5 to "My Group 2".

Get-NetFirewallRule -DisplayName 'My Rule 1' | ForEach { $_.Group = 'My Group 1'; Set-NetFirewallRule -InputObject $_ }

Get-NetFirewallRule -DisplayName 'My Rule 2' | ForEach { $_.Group = 'My Group 1'; Set-NetFirewallRule -InputObject $_ }

Get-NetFirewallRule -DisplayName 'My Rule 3' | ForEach { $_.Group = 'My Group 1'; Set-NetFirewallRule -InputObject $_ }

Get-NetFirewallRule -DisplayName 'My Rule 4' | ForEach { $_.Group = 'My Group 2'; Set-NetFirewallRule -InputObject $_ }

Get-NetFirewallRule -DisplayName 'My Rule 5' | ForEach { $_.Group = 'My Group 3'; Set-NetFirewallRule -InputObject $_ }

So in the firewall rule, first you fetch the firewall rule by using Get-NetFirewallRule cmdlet. Then for each result, you set the group to bying using $_.Group.

Result:







No comments:

Post a Comment

SQL Server Logical Reads vs Physical Reads

When it comes to SQL Server query tuning, two of the most used phrases are logical reads and physical reads. But do you know exactly what ar...