abilita log

da powershell:

Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True -LogMaxSizeKilobytes 20480 -LogFileName "$env:windir\system32\logfiles\firewall\pfirewall.log"

da cmd.exe:

powershell -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True -LogMaxSizeKilobytes 20480 -LogFileName \"\"%windir%\\system32\\logfiles\\firewall\\pfirewall.log\"\"'"

da batch:

@echo off
powershell -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True -LogMaxSizeKilobytes 20480 -LogFileName \"\"\"%windir%\\system32\\logfiles\\firewall\\pfirewall.log\"\"\"'"
pause

setta regola 162

DA powershell

New-NetFirewallRule -DisplayName "UDP 162 -OUT" -Direction Outbound -Action Block -Protocol UDP -RemotePort 162 -Profile Any -Enabled True -Description "Blocca tutto il traffico in uscita UDP sulla porta 162"

Da cmd.exe

powershell -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'New-NetFirewallRule -DisplayName \"UDP 162 -OUT\" -Direction Outbound -Action Block -Protocol UDP -RemotePort 162 -Profile Any -Enabled True -Description \"Blocca tutto il traffico in uscita UDP sulla porta 162\"'"

Versione più leggibile per script:

powershell -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'New-NetFirewallRule -DisplayName ""UDP 162 -OUT"" -Direction Outbound -Action Block -Protocol UDP -RemotePort 162 -Profile Any -Enabled True -Description ""Blocca tutto il traffico in uscita UDP sulla porta 162""'"

in un file batch (.bat):

@echo off
powershell -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'New-NetFirewallRule -DisplayName \"UDP 162 -OUT\" -Direction Outbound -Action Block -Protocol UDP -RemotePort 162 -Profile Any -Enabled True -Description \"Blocca tutto il traffico in uscita UDP sulla porta 162\"'"
pause

Quando eseguirai questo comando, comparirà la finestra UAC (User Account Control) e dovrai confermare l’elevazione dei privilegi per creare la regola firewall.