Windows – PowerShell Firewall Management

firewallpowershellwindowswindows-firewall

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”

Best Answer

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