We help IT Professionals succeed at work.
Get Started

Issues with using powershell to write to csv

YZlat
YZlat asked
on
496 Views
Last Modified: 2012-05-12
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?
Comment
Watch Question
This problem has been solved!
Unlock 3 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE