I have a script that needs to write to csv file. At first I just created a file with extension csv and wrote to is either tab or comma delimited values but then I would have trouble reading the csv from another script. If I used tab delimiters I had issues reading from file, if i used commas, the each row in csv would show up in the first column, and if i used both, comam and tab, commawould be written at the end of the column as part of the value
Here is the code I used:
$Headers="DateTimeStamp" + "`t" + "First" + "`t" + "Second" + "`t" + "Third"
$Headers| Out-File -Append -FilePath $LogFile -Encoding Unicode
$Values = $dtstamp + "`t" + $val1 + "`t""" + $val2 + """`t""" + $val3 + """"
$Values | Out-File -Append -FilePath $LogFile -Encoding Unicode
val2 and val3 need to have double quotes around them.
So I wanted to use export-csv cmdlet instead. the problem is that I understand how I can use export-csv to export datatable or data from a collection, but in my case i have to write line by line. So is it possible to use export-csv as an alternative to code above?