Link to home
Start Free TrialLog in
Avatar of hypercube
hypercubeFlag for United States of America

asked on

Using PowerShell on Windows Firewall #1

How to do this using PowerShell?

Add to the Remote Address scope in all of the private "File and Printer Sharing" rules.
Such as this netsh command would do:
netsh firewall set service type=fileandprint mode=enable scope=custom addresses=10.109.2.0/24,10.109.3.0/24,localsubnet profile =current

Similarly, add to the Remote Address scope in all of the private "Windows Instrumentation Management" rules and ensure they are enabled.
Avatar of Qlemo
Qlemo
Flag of Germany image

Assuming PowerShell 4 and W8 or above, the usable cmdlets are listed at https://technet.microsoft.com/en-us/library/jj554906(v=wps.630).aspx.
Get-NetFirewallRule -group '@FirewallAPI.dll,-28502' | set-NetFirewallRule -RemoteAddress 10.109.2.0/23,LocalSubnet4 -Enable true

Open in new window

Instead of -group '@FirewallAPI.dll,-28502' you could use the display name of the group, but this depends on the language. Since my system is german, I don't know the correct display name for you, it's probably 'File and Printer Sharing'. You can use wildcards if you like:
Get-NetFirewallRule -displaygroup 'File*' | set-NetFirewallRule -RemoteAddress 10.109.2.0/23,LocalSubnet4 -Enable true

Open in new window

Similar for WMI:
Get-NetFirewallRule -displaygroup '*WMI*' | set-NetFirewallRule -RemoteAddress 10.109.2.0/23,LocalSubnet4 -Enable true

Open in new window

Avatar of hypercube

ASKER

I figured it out through another question and I put up the answer here.

The responses here are really helpful as getting information a bit more efficiently is very much a part of using powershell.
I have been treating Private, Public and Domain as different rules because that's how they're listed in the Windows Firewall Advanced Settings.
However, I'm now wondering if powershell treats them as ONE with the profile specified as:

Public
Private
Domain
Public, Private
Public, Domain
Private, Domain
Public, Private, Domain

How does one change one and not the other?
I want to Disable Public and Domain and Enable Private.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!