0
 $employees = @()

#Add newly created object to the array
#$employees += $employee
for ($i=1;$i -le 2;$i++)
{
    $employee = New-Object System.Object
    $employee | Add-Member -MemberType NoteProperty -Name "Creation Time" -Value $(Get-date)
    $employee | Add-Member -MemberType NoteProperty -Name "Employee ID" -Value $($i.ToString("D2"))
    $employees += $employee
    Start-Sleep -Seconds 1
}


#Finally, use Export-Csv to export the data to a csv file
$employees | Export-Csv -NoTypeInformation -Path "c:\temp\test\EmployeeList.csv"

the result is

Creation Time     Employee ID

2014/10/14 1530      1

2014/10/14 1530      2

2014/10/14 1532      1

2014/10/14 1532      2

how can add the header...for examples

report<--title

Creation Time       Employee ID

2014/10/14 1530      1

2014/10/14 1530      2

2014/10/14 1532      1

2014/10/14 1532      2

1 Answer 1

1

It is not possible using Export-Csv cmdlet. You have to read the file into temp variable, write the header line and add csv content:

$csvPath = "c:\temp\test\EmployeeList.csv"
$eList = gc $csvPath
echo "report<--title" > $csvPath
$eList >> $csvPath
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.