Skip to content

Instantly share code, notes, and snippets.

@sad1e
Last active March 30, 2024 16:02
Show Gist options
  • Save sad1e/cf1cdf63a4247033ecebeb8c22c04182 to your computer and use it in GitHub Desktop.
Save sad1e/cf1cdf63a4247033ecebeb8c22c04182 to your computer and use it in GitHub Desktop.
script to add exe files to firewall outbound rules.
param(
[string]$DestPath = "",
[string]$GroupName = ""
)
if ([string]::IsNullOrEmpty($DestPath)) {
Write-Host "Destinationpath path is empty.";
return;
}
if (![System.IO.Directory]::Exists($DestPath)) {
Write-Host "Destination path is not exists."
return;
}
if ([string]::IsNullOrEmpty($GroupName)) {
Write-Host "GroupName is empty."
return;
}
$ExeFiles = Get-ChildItem -Path $DestPath -Recurse -Filter *.exe
foreach ($ExeFile in $ExeFiles) {
New-NetFirewallRule -Action Block -Program $ExeFile.FullName -Direction Outbound -Group $GroupName -DisplayName "$GroupName-$($ExeFile.BaseName)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment