> ## Content Index
> Fetch the complete content index at: https://note.xdq.me/llms.txt
> Use this file to discover other available public pages before exploring further.

# Powershell批量限制程序网络访问
- URL: https://note.xdq.me/powershellpi-liang-xian-zhi-cheng-xu-wang-luo-fang-wen/
- Published: 2025-06-13T03:55:18.000Z
- Updated: 2026-08-19T01:09:49.000Z
- Author: xud6
- Tags: windows, powershell, #Import 2026-10-03 02:45

```
$exeFileNames = Get-ChildItem -Path "C:\apps folder" -Recurse –File -Include "*.exe" | % { $_.FullName }

foreach ($exeFileName in $exeFileNames) {

    # Code to execute for each item
    Write-Host "----"
    Write-Host $exeFileName

    $existFirewallRule = Get-NetFirewallRule -DisplayName $exeFileName | Where-Object { $_.Action -eq 'Block' -and $_.Direction -eq 'Outbound' -and $_.Enabled -eq $True}
    if ($null -eq $existFirewallRule) {
        $newRule = New-NetFirewallRule -DisplayName $exeFileName -Direction Outbound -Program $exeFileName -Action Block
        Write-Host "Firewall rule created"
    }else {
        Write-Host "Firewall rule already exist"
    }
}

```