title: Powershell - Query firewall list of servers export to csv
body: <p>I'm using the following to query the firewall rules of a list of servers.</p>
  
  <pre><code>$servers = Get-Content fw_servers.txt
  
  foreach($serv in $servers) {
  $fw = New-Object -ComObject hnetcfg.fwpolicy2 
  
  $fw.rules | 
  
  Where-Object { $_.enabled -and $_.LocalPorts -like 3389 } | 
  
  Select-Object -Property direction,protocol, localports,name 
  }
  </code></pre>
  
  <p>I would like to export this information to a csv file. Can someone please let me know how I can use Export-CSV for this? I've tried making it into an array but it's not working for me. I'm using 2.0</p>
  
  <p>I'd also like the exported data to look like the following</p>
  
  <pre><code>Server    Direction   Protocol   LocalPorts    Name
  testsrv1  1           6          3389          Remote Desktop (TCP-In)
  testsrv2  1           6          3389          Research Remote Desktop Policy
  </code></pre>
  
  <p>Thank you for your help.</p>
  
  <p>Amelia</p>