PowerShell Firewall Management

12,984

Solution 1

Working on Windows Server 2012 R2 Core, this worked for me:

Set-NetFirewallRule -DisplayGroup "File And Printer Sharing" -Enabled True

Here is how to check if it was succesful

Get-NetFirewallRule -DisplayGroup "File And Printer Sharing"

And find the value in "Enabled", it should be set to TRUE.

More info and arguments can be found here:

Set-NetFirewallRule Technet

Solution 2

According to this article on Technet, only on Server 2012 or Windows 8: http://technet.microsoft.com/en-us/library/hh831755.aspx

Windows 7 and Server 2008 require Netsh, even with Powershell 4.0.

Share:
12,984

Related videos on Youtube

Jason
Author by

Jason

Updated on September 18, 2022

Comments

  • Jason
    Jason over 1 year

    I have a bunch of machines that I need to enable Remote Scheduled Tasks Management (RPC), Remote Scheduled Tasks Management (RPC-EPMAP), and Windows Management Instrumentation (WMI-in) on for GPO Updates.

    I would like to run a PowerShell script so I do not have to do this manually. However, I am new to powershell.

    Is there a way I can get the powershell command when I add the rules manually at a machine?

    EDIT:

    This is one way I found to do it:

    netsh advfirewall firewall set rule group="Remote Administration" new enable=yes
    netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=yes
    netsh advfirewall firewall set rule group="Remote Service Management" new enable=yes
    netsh advfirewall firewall set rule group="Performance Logs and Alerts" new enable=yes
    Netsh advfirewall firewall set rule group="Remote Event Log Management" new enable=yes
    Netsh advfirewall firewall set rule group="Remote Scheduled Tasks Management" new enable=yes
    netsh advfirewall firewall set rule group="Remote Volume Management" new enable=yes
    netsh advfirewall firewall set rule group="Remote Desktop" new enable=yes
    netsh advfirewall firewall set rule group="Windows Firewall Remote Management" new enable =yes
    netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable =yes
    

    However, I have to execute it on every machine.

    For some reason, this one does not work:

    Enable-NetFirewallRule -DisplayGroup “Windows Remote Management”
    
  • Koen Zomers
    Koen Zomers almost 8 years
    To enable it for specific access (i.e. domain, public, private networks), add the -Profile Domain|Public|Private argument.