How to Modify Firewall Address Filter

How to Modify Firewall Address Filter

CHUONG K. NGUYEN – BSc., MCSEx2, MCSAx2, MCP, MCTS, MCITP, CCNA

We need to add the IP addresses (using host names) to the Remote Address list in the Firewall Rules. Note: The new IP added might be duplicates with the existing ones but next time it will be removed.

$ips = (Get-NetFirewallRule -DisplayName "Test Rule" | Get-NetFirewallAddressFilter ).RemoteAddress | Sort-Object -Unique

$AllHosts = @('www.host1.com','www.host2.com')

foreach ($curhost in $AllHosts) {
	$dynhost = [System.Net.Dns]::GetHostAddresses($curhost.ToString())
	$address = $dynhost.IPaddresstostring
	$ips += $address 
}

Set-NetFirewallRule -DisplayName "Test Rule" -RemoteAddress $ips
Write-Host "The following IP has been added to the Firewall Address Filter: ", $ips