Powershell批量限制程序网络访问

$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"
    }
}