title: PowerShell : writing to text file
body: <p>I am trying to get a list installed printers for a list of computer. </p>
  
  <p>When I run this script, it only "writes" the last computer's information. </p>
  
  <p>I am VERY new to PS and would appreciate some help. </p>
  
  <pre><code>$filePath = "E:\ps\computerswithprinters.txt"
  $class = "win32_printer"
  $arycomputer = Get-Content "E:\ps\computers.txt"
  
  foreach( $computer in $aryComputer)
  {
     Write-Host "Retrieving printers from $computer ..."
     $wmi = Get-WmiObject -Class $class -computername $computer
     format-table -Property name, systemName, shareName -groupby driverName `
                  -inputobject $wmi -autosize | Out-File -FilePath $filePath 
  }
  </code></pre>
  
  <p>Thank you in advance!</p>