title: How can I stop the Powershell command `Get-NetFirewallRule` from throwing an error?
body: <p>I'm trying to determine if a firewall rule exists or not, with Powershell.</p>
  
  <p>If the rule does <em>not</em> exist, I get an ugly error message. If it does exist, all is good :)</p>
  
  <p>How can I check if the rule exists without any ugly red error message occuring?</p>
  
  <p>eg.</p>
  
  <pre><code>Import-Module NetSecurity
  
  # Check if the firewall rule exists.
  $existingRule = Get-NetFirewallRule -DisplayName $name
  </code></pre>
  
  <p>Error message (when the rule doesn't exist)...</p>
  
  <pre><code>Get-NetFirewallRule : No MSFT_NetFirewallRule objects found with property 'DisplayName' equal to 'Blah Blah Port 44444'.  Verify the value of the property and retry. At C:\projects\xwing\Setup.ps1:67 char:21
  +     $existingRule = Get-NetFirewallRule -DisplayName $name
  +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (Blah Blah Port 44444:String) [Get-NetFirewallRule], CimJobException
      + FullyQualifiedErrorId : CmdletizationQuery_NotFound_DisplayName,Get-NetFirewallRule
  </code></pre>
  
  <p>Anyone know how to safely check for a rule, please?</p>