Set NetFirewallProfile - PowerShell


Overview

Set-NetFirewallProfile configures settings for the Windows Firewall profiles on your local computer. It allows you to enable or disable the firewall, change profile types, and set advanced firewall policies.

Syntax

Set-NetFirewallProfile [-Name] <string> [-DisplayName] <string> [-Enabled] <bool> [-DefaultInboundAction] <FirewallAction>
[-DefaultOutboundAction] <FirewallAction> [-AllowInbound] <bool> [-AllowOutbound] <bool> [-BlockInboundByDefault] <bool>
[-BlockOutboundByDefault] <bool> [-ProfileType] <FirewallProfileType> [-Description] <string>

Options/Flags

  • -Name: Specifies the profile name to configure.
  • -DisplayName: Sets the display name for the profile.
  • -Enabled: Enables or disables the firewall for the specified profile.
  • -DefaultInboundAction: Sets the action taken for inbound traffic that does not match any firewall rules.
  • -DefaultOutboundAction: Sets the action taken for outbound traffic that does not match any firewall rules.
  • -AllowInbound: Controls whether all inbound traffic is allowed.
  • -AllowOutbound: Controls whether all outbound traffic is allowed.
  • -BlockInboundByDefault: Sets whether to block all inbound traffic by default.
  • -BlockOutboundByDefault: Sets whether to block all outbound traffic by default.
  • -ProfileType: Specifies the type of profile to create or modify (Domain, Public, Private).
  • -Description: Sets a description for the profile.

Examples

Example 1: Enable the firewall for the Public profile

Set-NetFirewallProfile -Name Public -Enabled $true

Example 2: Set the default inbound action to Block for the Private profile

Set-NetFirewallProfile -Name Private -DefaultInboundAction Block

Example 3: Allow all outbound traffic for the Domain profile and disable the firewall

Set-NetFirewallProfile -Name Domain -AllowOutbound $true -Enabled $false

Example 4: Create a new profile named “MyProfile” with a custom description

Set-NetFirewallProfile -Name MyProfile -ProfileType Private -Description "My custom firewall profile"

Common Issues

Issue: “Set-NetFirewallProfile: Failed to set firewall profile.”

Solution: Ensure you have administrator privileges and that the Windows Firewall service is running.

Integration

Integration with Group Policy: You can use Set-NetFirewallProfile in Group Policy scripts to configure firewall settings across multiple computers in a domain.

  • Get-NetFirewallProfile: Retrieves information about firewall profiles.
  • New-NetFirewallProfile: Creates a new firewall profile.
  • Remove-NetFirewallProfile: Deletes a firewall profile.