How to Disable Windows Firewall Using PowerShell?

In this tutorial, I will explain how to disable the Windows Firewall using PowerShell. As an IT administrator for a company based in the USA, I recently faced an issue where I needed to streamline the process of managing the Windows Firewall across multiple networked machines. After some research, I found that PowerShell provides an efficient method to enable or disable Windows Firewall profiles.

Disable Windows Firewall Using PowerShell

PowerShell allows you to easily disable the Windows Firewall across multiple machines in your network.

Follow the below steps to disable the Windows firewall.

Step 1: Open PowerShell as Administrator

To get started, you need to open PowerShell with administrative privileges. Follow these steps:

  1. Press the Windows key + X to open the Quick Access Menu
  2. Select “Windows PowerShell (Admin)” from the list
  3. Click “Yes” when prompted by the User Account Control (UAC) dialog

Step 2: Check the Current Firewall Status

Before disabling the Windows Firewall, it’s a good practice to check its current status. Run the following command in PowerShell:

Get-NetFirewallProfile | Format-Table -Property Name, Enabled

This command will display the status of each firewall profile (Domain, Private, and Public) in a table format.

I executed the above PowerShell script on my local machine, and you can see the exact output in the screenshot below:

Disable Windows Firewall Using PowerShell

Check out Rename a Windows Computer Using PowerShell

Step 3: Disable the Windows Firewall

To disable the Windows Firewall for all profiles, use the following command:

Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False

This command sets the “Enabled” property of all three firewall profiles to “False,” effectively disabling the firewall.

If you want to disable the firewall for a specific profile, simply remove the other profiles from the command. For example, to disable only the Public profile:

Set-NetFirewallProfile -Profile Public -Enabled False

Step 4: Verify the Firewall Status

After running the command to disable the firewall, it’s crucial to verify that the changes have taken effect. Run the command from Step 2 again:

Get-NetFirewallProfile | Format-Table -Property Name, Enabled

The output should now show that the specified profiles are disabled (Enabled = False).

Check out Find Logged In User Using PowerShell

Disable Specific Firewall Rules using PowerShell

In some cases, you may want to disable specific firewall rules instead of turning off the entire firewall. PowerShell allows you to manage individual rules using the Disable-NetFirewallRule cmdlet.

To disable a specific rule, you need to know its name or a unique identifier. You can retrieve a list of all firewall rules using the following command:

Get-NetFirewallRule

Once you have identified the rule you want to disable, use the Disable-NetFirewallRule cmdlet followed by the rule name. For example:

Disable-NetFirewallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)"

This command disables the firewall rule responsible for allowing incoming ICMPv4 echo requests (ping) for file and printer sharing.

Read Find Installed Software Using PowerShell

Enable the Windows Firewall using PowerShell

To re-enable the Windows Firewall, simply replace “False” with “True” in the commands from Step 3. For example, to enable the firewall for all profiles:

Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled True

Similarly, you can use the Enable-NetFirewallRule cmdlet to enable specific firewall rules that were previously disabled.

Automate Firewall Management with PowerShell Scripts

PowerShell scripts allow you to automate the process of managing the Windows Firewall across multiple machines in your network. By creating a script that includes the necessary commands, you can easily disable or enable the firewall on remote computers without having to manually intervene on each machine.

Here’s a simple example of a PowerShell script that disables the Windows Firewall on a remote computer:

$computer = "RemotePC"

Invoke-Command -ComputerName $computer -ScriptBlock {
    Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False
}

In this script, the $computer variable holds the name of the remote computer. The Invoke-Command cmdlet is used to execute the Set-NetFirewallProfile command on the specified remote machine.

You can expand this script to include multiple remote computers by using an array or reading the computer names from a file.

Conclusion

In this tutorial, I explained how to disable Windows firewall using PowerShell using simple commands. I have also shown how to disable specific firewall rules using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.