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