Skip to content

Instantly share code, notes, and snippets.

@sad1e
Last active March 30, 2024 16:02
Show Gist options
  • Select an option

  • Save sad1e/cf1cdf63a4247033ecebeb8c22c04182 to your computer and use it in GitHub Desktop.

Select an option

Save sad1e/cf1cdf63a4247033ecebeb8c22c04182 to your computer and use it in GitHub Desktop.

Revisions

  1. sad1e revised this gist Mar 30, 2024. No changes.
  2. sad1e created this gist Mar 30, 2024.
    23 changes: 23 additions & 0 deletions disable_exe_conn.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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)"
    }