by RLewis123 at 2012-12-05 11:11:17
I have an array that contains a number of items with a single item on each line. I need to append a txt file with this array info but when I do that the .txt file has all the lines appear on a single line. How can I take this array info and use it to append a file and still get the newlines that are in it to show up?by RLewis123 at 2012-12-05 11:58:05
I’ve used a foreach on the array like this:
foreach ($lineitem in $Array){add-content -path $LogFile "$lineitemn"}</blockquote>by iHunger at 2012-12-05 11:26:20<blockquote>Just guessing, but you might need a <strong>rn</strong> instead of just <strong>n.
Tried it - no joy. Thanks anyway.by RichardSiddaway at 2012-12-05 12:16:31
The Array appears fine onscreen, in an e-mail and even works if I output to a CSV format file but the minute I’m outputting to a .TXT format file and opening in Notepad it all displays on a single line.
Does this solve your problem?by RLewis123 at 2012-12-05 13:15:23$data = "AAA", "BBB", "CCCC", "DDD"
Add-Content -Path C:\test\test.txt -Value $data
get-content -Path C]
Just makes sure you have a line feed after the last line in the file before you add the array
Richard - The Array I have is being created by code that looks like this:by RLewis123 at 2012-12-05 16:22:59
$array += "$strComputer1 blah1n"<br>$array += "$strComputer2 blah2n"
$array += "$strComputer3 blah3n"<br>$array += "$strComputer4 blah4n"
In the end this is creating an array that appears to have newline chars in it but displays on a single line when placed into a TXT file.
OK - the `r did the trick after all - inserted it at a different location. Many thanks!