Search code examples
powershelltcprpcpowershell-5.0windows-firewall

How can I replicate a RPC firewall entry using New-NetFirewallRule in Powershell?


I'm working on a deployment script for Windows Server 2012R2 that has to replicate some firewall enrties. The New-NetFirewallRule cmdlet works fine for simple rules but I'm not able to make this custom one work through powershell :

Rule I'm trying to replicate

According to Technet documentation :

If the Protocol parameter value is TCP or UDP, then the acceptable values for this parameter are:
-- Port range: 0 through 65535.
-- Port number: 80.
-- Keyword: PlayToDiscovery or Any.

If the Protocol parameter value is ICMPv4 or ICMPv6, then the acceptable values for this parameter are:
-- An ICMP type, code pair: 0, 8.
-- Type and code: 0 through 255.
-- Keyword: Any.

If the Protocol parameter is not specified, then the acceptable values for this parameter are: RPC, RPCEPMap, Teredo, IPHTTPSIn, IPHTTPSOut, or Any.

So I can't figure how to define a rule that uses Protocol=TCP and Local Port="RPC Dynamic Ports". Could anyone throw some light here? :)


Solution

  • I found that specifying "RPC" as the parameter value for -LocalPort and "TCP" for -Protocol parameter will create a rule with the values you are looking for.

    Example:

    New-NetFirewallRule -Name 'Name' -DisplayName 'Name' -Group 'Group' -Profile Domain -Direction Inbound -Action Allow -EdgeTraversalPolicy Block -Protocol 'TCP' -LocalPort 'RPC'