Concatinate a ","/common to each item in a file RRS feed

  • Question

  • I'm trying to concatenate a ","/common at the end of each object in an array as it is being exported to the destination.  Below is what I've tired but its not working:

    ($dt | convertTo-csv -Delimiter ',' -NoTypeInformation) |foreach-object {+ ","} |Select -Skip 1 | Out-File -Append $ExtractFile

    What I'm I missing?


    • Moved by Bill_Stewart Tuesday, December 5, 2017 3:14 PM Unanswerable drive-by question
    Thursday, October 26, 2017 1:01 AM

All replies

  • Could you please use the code posting tool when you post code? Thanks.

    What do you actually try to accomplish? What you're asking for does not make that much sense IMO.

    Best regards (79,108,97,102|%{[char]$_})-join''

    Thursday, October 26, 2017 7:28 AM
  • It is necessary to specify the column in you code.

    The convert to csv adds the commas so you do not need to add them

    $dt | Export-csv  $ExtractFile -NoType -Append


    Thursday, October 26, 2017 9:12 AM
  • I want to add a character at the end of each line.  In this case that character is a comma/",".  Before the data reaches its final destination.  


    Thursday, October 26, 2017 12:16 PM
  • Why?  That would not create a CSV.  It would create a broken text file.

    The output of "ConverTo-Csv" is not a string it is a collection of objects.  You cannot add a string to it.

    To add an empty field to a collection do this:

    $dt |select *,@{n-'Extra';e=(''}}Export-csv  $ExtractFile -NoType -Append


    Thursday, October 26, 2017 12:23 PM