Here is the C# code to return Firewall rules:
Type tNetFwPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
INetFwPolicy2 fwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(tNetFwPolicy2);
List<INetFwRule> RuleList = new List<INetFwRule>();
foreach (INetFwRule rule in fwPolicy2.Rules)
{
RuleList.Add(rule);
}
With Powershell this returns the same:
Get-NetFirewallRule
However Powershell also has the -PolicyStore param. If we use:
Get-NetFirewallRule -PolicyStore RSOP
or
Get-NetFirewallRule -PolicyStore ActiveStore
It will return all the rules enforced by the domain group policy.
Is there something similar that can be done with C#?