none
Overwriting Powershell Output to Excel RRS feed

  • Question

  • I am wondering how to control the output from powershell to Excel or CSV.  I have a script that runs through hundreds of computers and when it outputs to excel and CSV it continuously overwrites the first row instead of going to a new row for each machine.  I have looked through the script and I can't find any command such as the "nonewrow" command.  What commands do I need to add to the script in order to make it advance to the next row?
    Friday, March 21, 2014 1:20 PM

Answers

All replies

  • Hi,

    The best thing to do is to build your entire object and then export it to CSV. Alternatively, you can start adding the -Append parameter to Export-Csv (requires at least V3 if I remember correctly), but this will be slow.


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Friday, March 21, 2014 1:42 PM
  • Hi,

    another option is to preassemble each line and immediately write it as a new line in a filestreamwriter. That should be significantly faster and still be easy on the memory.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Friday, March 21, 2014 1:50 PM
  • My guess is that you're trying to write procedural code instead of taking advantage of the pipeline.

    My recommendation is to output the objects you want, and then export-csv afterward.


    -- Bill Stewart [Bill_Stewart]

    Friday, March 21, 2014 2:44 PM
    Moderator