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

Franz Schenk 341 Reputation points
2021-09-22T15:23:55.95+00:00

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:

134363-firewall.png

"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.
Franz

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,931 questions
0 comments No comments
{count} vote

Accepted answer
  1. Castorix31 85,956 Reputation points
    2021-09-22T16:02:45.267+00:00

    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
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,686 Reputation points
    2021-09-23T08:20:29.307+00:00

    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.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.