Skip to content

Instantly share code, notes, and snippets.

@peetrike
Last active June 14, 2022 14:01
Show Gist options
  • Save peetrike/4636036304bfd2bb598a69d2eb31d49f to your computer and use it in GitHub Desktop.
Save peetrike/4636036304bfd2bb598a69d2eb31d49f to your computer and use it in GitHub Desktop.
Create address filter for reaching remote server, if it's network connection is Public
#Requires -Modules NetSecurity
# Remote admin network
$RemoteNet = '1.2.3.4/255.255.255.248'
$AddressFilter = Get-NetFirewallRule -Group '@FirewallAPI.dll,-30267' |
Where-Object Profile -like 'Public' |
Get-NetFirewallAddressFilter
if ($AddressFilter.RemoteAddress -NotContains $RemoteNet) {
$remoteFilter = @($AddressFilter.RemoteAddress) + $RemoteNet
$AddressFilter | Set-NetFirewallAddressFilter -RemoteAddress $remoteFilter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment