#
# manage firewall with powershell
#
# http://woshub.com/manage-windows-firewall-powershell/
#
# all commands must be executet with administrative rights
#
# whole list of commands
Get-Command -Module NetSecurity
# get settings
Get-NetFirewallSetting
# list firewall rules
Get-NetFireWallRule
Get-NetFireWallRule | select displayname, enabled, profile
# list firewall profiles
Get-NetFirewallProfile | select Name, Enabled
# get file and printer sharing rules
Get-NetFirewallRule -DisplayGroup 'Datei- und Druckerfreigabe' | Format-Table
# get file and printer port rules
Get-NetFirewallRule -DisplayGroup 'Datei- und Druckerfreigabe' | Get-NetFirewallPortFilter | Format-Table
# get rule for remote desktop
Get-NetFirewallRule -DisplayGroup 'RemoteDesktop' | Format-Table
# get all ipv6 rules
Get-NetFirewallRule | Where Name -like '*ipv6*' | Format-Table
# enable all three network profiles: Domain, Public and Private
Set-NetFirewallProfile -All -Enabled True
# disable all three network profiles: Domain, Public and Private
#Set-NetFirewallProfile -All -Enabled False
# allow ping (ICMP) for addresses from the specified IP subnet or IP range
$ips = @(“192.168.2.15-192.168.2.40”, “192.168.100.15-192.168.100.200”, ”10.1.0.0/16”)
New-NetFirewallRule -DisplayName “Allow inbound ICMPv4”
-Direction Inbound -Protocol ICMPv4 -IcmpType 8 -RemoteAddress $ips
-Action Allow
New-NetFirewallRule -DisplayName “Allow inbound ICMPv6”
-Direction Inbound -Protocol ICMPv6 -IcmpType 8 -RemoteAddress $ips
-Action Allow
# to list all ICMP rules
Get-NetFirewallRule |select displayname, enabled, action, profile |where displayname -like '*icmp*'
# to list all ICMP rules, incomming
Get-NetFirewallRule |select displayname, enabled, action, profile |where displayname -like '*icmp*', '*eingehend*'
# change the default action for the Public profile to block all inbound connections
Set-NetFirewallProfile –Name Public –DefaultInboundAction Block
# allow inbound TCP connections to ports 80 and 443 for Domain and Private profiles
New-NetFirewallRule -DisplayName 'HTTP-Inbound' -Profile
@('Domain', 'Private') -Direction Inbound -Action Allow -Protocol TCP
-LocalPort @('80', '443')
Microsoft: Windows Defender Firewall mit erweiterter Sicherheitsverwaltung mit Windows PowerShell