Block an IP Address with a Windows Firewall Rule
Create a deny rule for an IP or subnet with one PowerShell command — no GUI digging required.
01Command
$ New-NetFirewallRule -DisplayName "Block Bad Host" -Direction Inbound -RemoteAddress 203.0.113.55 -Action Block02What it does
-RemoteAddress accepts a single IP, an IP range like 203.0.113.0-203.0.113.255, or a CIDR subnet such as 10.0.0.0/8, so you can block a whole misbehaving network. Rules created this way appear in Windows Security > Firewall & network protection > Advanced settings and persist across reboots. Add a second rule with -Direction Outbound if you also want to stop your PC from talking to that host.
03Risk
04Undo
$ Remove-NetFirewallRule -DisplayName "Block Bad Host"05Sources
- New-NetFirewallRule (NetSecurity)Evidence: Documents -DisplayName, -Direction, -RemoteAddress and -Action (Allow/Block) parameters with firewall rule examples.
- NetSecurity module referenceEvidence: Module reference lists New-NetFirewallRule and Remove-NetFirewallRule for managing firewall rules.
Last verified: 2026-09-19 · Category: Security & Privacy
06Related solutions
Read the Authenticode signature status and signer of any executable or script in PowerShell.
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.
Search inside text files and logs with regex, returning file, line number and match.