-
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.
Retrieving All Firewall Outbound Ports & Program Exceptions
- Loading branch information
1 parent
5524cf4
commit b6273f8
Showing
1 changed file
with
36 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,36 @@ | ||
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
# Name : List-Firewall-Outbound-Ports-ProgramExceptions.ps1 | ||
# Author : Harsh Arora | ||
# Description : This powershell script uses calculated properties to retrieve all firewall Outbound Ports with Program Exceptions with cmdlet Select-Object and export it to CSV format. | ||
#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
$Logfile = "$env:SystemDrive\ListAllFirewallOutboundRules.log" | ||
$ExportFirewallOutboundCSV = "$env:SystemDrive\AvailableFirewallOutboundRules.csv" | ||
|
||
function LogWrite([string]$logstring) | ||
{ | ||
$DateTime = Get-Date -Format g | ||
Add-content $Logfile -value "$DateTime $logstring" | ||
} | ||
|
||
$Return = Get-NetFirewallRule -Direction Outbound | | ||
Select-Object -Property DisplayName, | ||
DisplayGroup, | ||
Profile, | ||
Enabled, | ||
Action, | ||
@{Name='Program';Expression={($PSItem | Get-NetFirewallApplicationFilter).Program}}, | ||
@{Name='LocalAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).LocalAddress}}, | ||
@{Name='RemoteAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).RemoteAddress}}, | ||
@{Name='Protocol';Expression={($PSItem | Get-NetFirewallPortFilter).Protocol}}, | ||
@{Name='LocalPort';Expression={($PSItem | Get-NetFirewallPortFilter).LocalPort}}, | ||
@{Name='RemotePort';Expression={($PSItem | Get-NetFirewallPortFilter).RemotePort}}| Export-CSV -NoType $ExportFirewallOutboundCSV | ||
|
||
If($? -eq $true) | ||
{ | ||
LogWrite "Exporting of all Windows Firewall Outbound Rules with Port Numbers and Program Exceptions in CSV format at location: '$ExportFirewallOutboundCSV' and returned: $?" | ||
} | ||
else | ||
{ | ||
LogWrite "Failed to export all Windows Firewall Outbound Rules with Port Numbers and Program Exceptions in CSV format at location: '$ExportFirewallOutboundCSV' and returned: $?" | ||
} |