我正在使用以下内容从一大堆文本文件中读取一行,然后将该信息汇总到一个文件中。
$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
}
当我运行代码时,Write-Output 按预期输出所有记录,但 Export-CSV 仅包含最后一条记录。我究竟做错了什么?