How do I enable ping in Windows firewall using PowerShell?

Posted: (EET/GMT+2)

 

For the last ten years at least, I've relied on the Windows "netsh" command to set Windows firewall rules automatically in various environments, be it testing, development, or production. But as more and Windows management automation commands shift to PowerShell, I thought it's time to learn a new way to update Windows firewall rules using PowerShell.

It turns out there's a command called New-NetFirewallRule, which is part of the NetSecurity module.

For example, to allow Ping echo requests (ICMP version 4 messages), you could run the following command:

PS C:\>New-NetFirewallRule -DisplayName "Allow Ping (ICMPv4)" -Direction Inbound
-Protocol ICMPv4 -IcmpType 8 -Profile Any -Action Allow

Hope this helps!