Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

Ensure Firewall Rule

Ensures the existence of a firewall rule on a Windows server.

Script usage:

Firewall::Ensure-NetFirewallRule(
	Name: <text>,
	Profiles: <text>,
	Port: <text>,
	Protocol: <text>,
	Inbound: <true/false>,
	Allow: <true/false>,
	[Exists: <true/false>]
);

Arguments:

NameFormatScript UsageUsage Notes
Name
text
Name
This argument is required.
Profiles
text
Profiles
Specify a comma separated list of profiles: "Public", "Private", and/or "Domain". (ex: "Public, Private"). This argument is required.
Port or Port Range
text
Port
Specify the port(s) affected by the firewall rule. Ports can be a comma separated list or a port range specified as "start-end" ex: 80-81,443. This argument is required.
Protocol
text
Protocol
Specify if the protocol is "UDP" or "TCP". This argument is required.
Inbound
true/false
Inbound
Specify if the connection is Inbound or Outbound. (Default = true). Default value is "True". This argument is required.
Allow
true/false
Allow
Select if you want to Allow or Block a connection. (Default = true). Default value is "True". This argument is required.
Exists
true/false
Exists
Default value is "True".

Example:

# ensures that TCP ports 80 and 443 are allowed on "Domain" and Private profiles in Window's Firewall
Firewall::Ensure-NetFirewallRule(
    Name: OtterHttpTCP80443,
    Profiles: "Domain, Private",
    Port: "80,443",
    Protocol: TCP,
    Inbound: true,
    Allow: true
);

# ensures that UDP ports 5000 through 5004 and 5008 are allowed on the "Domain" profile Window's Firewall
Firewall::Ensure-NetFirewallRule(
    Name: OtterHttpUdpTest,
    Profiles: "Domain",
    Port: "5000-5004,5008",
    Protocol: UDP,
    Inbound: true,
    Allow: true
);

# ensures that the "OtterHttpTCP80443" Window's Firewall rule is removed
IIS::Ensure-Site(
    Name: OtterHttpTCP80443,
    Exists: false
);