I'm using the following to read one line from a whole load of text files and then summarize that information into one file.
$computers = Get-content computers.txt
$users = users.csv
$header = 'Computer','User','Date','Time'
Foreach ($computer in $computers)
{
$file = $computer +'.txt'
$a = import-csv $file -Header $header | Select -first 1
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Computer ($a.Computer)
$obj | Add-Member NoteProperty User ($a.User)
$obj | Add-Member NoteProperty Date ($a.Date)
$obj | Add-Member NoteProperty Time ($a.Time)
Write-Output $obj
$obj | Export-csv -path $users -notype
}
When I run the code the Write-Output outputs all the records as expected, but the Export-CSV only contains the last record. What am I doing wrong?