Skip to content

Instantly share code, notes, and snippets.

@deejayy
Created November 17, 2022 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deejayy/9fac4acc1aeefc9289efb7f71c9325df to your computer and use it in GitHub Desktop.
Save deejayy/9fac4acc1aeefc9289efb7f71c9325df to your computer and use it in GitHub Desktop.
Add exceptions to Windows firewall based on blocked connections
Get-EventLog -Log Security -Newest 100 -InstanceId 5152 -Message "*%%14593*" | Sort-Object -Property TimeGenerated | Select-Object -ExpandProperty Message | ? { $_ -notlike "*svchost*" } | % { $_ -split "\r\n" } | ? { $_ -like "*Application Name*" -or $_ -like "*Destination*" } | % { $_ -replace "\\device\\harddiskvolume.",":" }
$path = Read-Host 'Path: '
$appName = Read-Host 'App name: '
$date = Get-Date -Format "yyyy-MM-dd"
Write-Output "XX $appName / $date"
New-NetFirewallRule -DisplayName "XX $appName / $date" -Direction Outbound -Program $path -Action Allow
--
Runner.bat:
@echo off
powershell.exe -Command "Start-Process powershell.exe -Verb RunAs D:\bin\batch\addfw.ps1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment