Windows firewall: How to block all incoming connections with PowerShell?

Franz Schenk 296 Reputation points

Have to manage Windows firewall settings with Powershell, and have to configure the Windows firewall to not allow any incoming connections. All the automatically created firewall exception rules that Windows creates should also be blocked. We need the configuration for any Firewall profile according the following printscreen:


"set-netfirewallprofile -all -DefaultInboundAction Block " blocks incoming connections, but allows all the configured inbound rules. A parameter like "-DefaultInboundActions Blockall" seem not to exist and does not work.

Any advice how to get the configuration according the printscreen with Powershell? Thank you in advance for any help.

PS: Group Policy is not an option, we have to deploy Workgroup clients.

Windows 10 Security
Windows 10 Security
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
2,323 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 71,606 Reputation points

    On Windows 10 1909, I can set to "Block all" with , as Admin :
    (1 as parameter is for NET_FW_PROFILE2_DOMAIN)

    $fwp = New-Object -ComObject hnetcfg.fwpolicy2
    $fwp.BlockAllInboundTraffic(1) = 1
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 37,746 Reputation points

    Hello Franz,

    I also ignore if there is a equivalent in Powerhshell, but I have been using it from prompt:

    to enable:

    netsh advfirewall set domainprofile firewallpolicy blockinboundalways,allowoutbound

    to disable:

    netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound

    Hope this helps,

    --If the reply is helpful, please Upvote and Accept as answer--

    1 person found this answer helpful.