PowerShell Genie

Set-NetFirewallRule

Use Set-NetFirewallRule to change properties of existing Windows Firewall rules.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> Set-NetFirewallRule [-Name] <String[]> [-DisplayName <String>] [-Enabled <Enabled>] [-Action <Action>] [-Direction <Direction>] [-Profile <Profile>] [-LocalPort <String[]>] [-RemoteAddress <String[]>] [-WhatIf] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Set-NetFirewallRule [-Name] <String[]> [-DisplayName <String>] [-Enabled <Enabled>] [-Action <Action>] [-Direction <Direction>] [-Profile <Profile>] [-LocalPort <String[]>] [-RemoteAddress <String[]>] [-WhatIf] [<CommonParameters>]
  1. Stage 1Set-NetFirewallRule-Name -DisplayName -Enabled -Action -Direction -Profile -LocalPort -RemoteAddress -WhatIf

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Set-NetFirewallRule -DisplayName "Remote Desktop - User Mode (TCP-In)"

    1PS> Set-NetFirewallRule -DisplayName "Remote Desktop - User Mode (TCP-In)" -Enabled True
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name                                  DisplayName                         Enabled Direction Action
    ----                                  -----------                         ------- --------- ------
    e7c9f4a2-3b5d-4e8f-9a1c-2d6b7e5f8a9c  Remote Desktop - User Mode (TCP-In)  True    Inbound   Allow

    Parameters

    Parameter definitions:

    • -Name
    • -DisplayName
    • -Enabled
    • -Action
    • -Direction
    • -Profile
    • -LocalPort
    • -RemoteAddress
    • -WhatIf

    PowerShell module reference on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Set-NetFirewallRule when you need to change properties of existing Windows Firewall rules. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: Access denied or an unchanged effective rule can reflect policy management. Check elevation and whether Group Policy owns the rule before trying to modify local settings. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Get-NetFirewallRule. Set-NetFirewallRule changes existing firewall rule settings; Get-NetFirewallRule reads them. Record the original rule and its policy source before applying a change. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Set-NetFirewallRule reference on Microsoft Learn

    Recap

    Set-NetFirewallRule Use Set-NetFirewallRule to change properties of existing Windows Firewall rules.

    Next: Get-NetFirewallRule
    Genie guideSet-NetFirewallRule

    Use Set-NetFirewallRule to change properties of existing Windows Firewall rules. The console below is pre-loaded — run it, then change a value and run it again.