-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Firewall Group Rules will be deleted based on command-line arguments
- Loading branch information
1 parent
9f49ca3
commit 1ea974e
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# --------------------------------------------------------------------------------------------------------------------------------- | ||
# Name : Remove-Firewall-Group-Rules.ps1 | ||
# Author : Harsh Arora | ||
# Description : This powershell script removes either Windows Firewall Inbound or Outbound Group Rules which will be passed | ||
# as a command-line argument using powershell cmdlets | ||
# Arguments : $GroupName, $Direction | ||
# --------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
$GroupName = $args[0] | ||
$Direction = $args[1] | ||
$Logfile = "$env:SystemDrive\RemoveFirewallGroupRule.log" | ||
$ExportFirewallGroupRules = "$env:SystemDrive\ListFirewallGroupRules.csv" | ||
$PSFirewallGroupRule = Get-NetFirewallRule -DisplayGroup "$GroupName" -Direction $Direction | Export-Csv -NoTypeInformation $ExportFirewallGroupRules | ||
|
||
function LogWrite([string]$logstring) | ||
{ | ||
$DateTime = Get-Date -Format g | ||
Add-content $Logfile -value "$DateTime $logstring" | ||
} | ||
|
||
LogWrite "Searching Windows Firewall Group Rule Name : '$GroupName' in direction: '$Direction'" | ||
|
||
#Delete all the matching Firewall Group Rules | ||
If($GroupName -ne $null) | ||
{ | ||
$PSFirewallGroupRule | ||
$Return = Get-NetFirewallRule -DisplayGroup "$GroupName" -Direction $Direction | Remove-NetFirewallRule | ||
|
||
If ($? -eq $false) | ||
{ | ||
LogWrite "Not found, so can't delete all the matching Firewall Group Rule Name: '$GroupName' from Direction: '$Direction' and returned: $?" | ||
} | ||
else | ||
{ | ||
LogWrite "Found, so deleting all the matching Firewall Group Rule Name: '$GroupName' from Direction: '$Direction' and returned: $?" | ||
} | ||
} |