title: Out-File only show last line
body: <p>I'm trying o get <code>netstat</code> output in to an out file. The script works well without the <code>Out-File</code>, I see everything on the console. However, when I do use <code>Out-File</code>, I only see the last line.</p>
  
  <pre><code>$ComputerName = Read-Host -Prompt 'Please Input Computer Name'
  $cmd = netstat -nao | Select-String "ESTA"
  foreach ($element in $cmd) {
    $data = $element -split ' ' | where {$_ -ne ''}
    New-Object -TypeName PSObject -Property @{
      'Local IP : Port#'   = $data[1];
      'Remote IP : Port#'  = $data[2];
      'Process ID'         = $data[4];
      'Process Name'       = ((Get-Process | where {$_.ID -eq $data[4]})).Name
      'Process File Path'  = ((Get-Process | where {$_.ID -eq $data[4]})).Path
      'Process Start Time' = ((Get-Process | where {$_.ID -eq $data[4]})).StartTime
      #'Process File Version' = ((Get-Process | where {$_.ID -eq $data[4]})).FileVersion
      'Associated DLLs and File Path' = ((Get-Process | where {$_.ID -eq $data[4]})).Modules |
        select @{Name='Module';Expression={$_.Filename -join ';  '}} |
        Out-File -FilePath c:\temp\net.txt
    }
  }
  </code></pre>