1

Ich have got an array with names called $arraylist_user. I run with a for-loop through out the array. On every loop I output the text

echo "User:" $arraylist_user[$i] "isn´t in the office!" | Out-File -FilePath "C:\Temp\test.txt" -Append -encoding unicode through a txt-File.

I got every part in a newline. Like:

User:
Tom
isn´t in the office!

How can I get the complete sentence User: Tom isn´t in the office! in one line in the text file.

I tried:

echo -NoNewLine "User:" $arraylist_user[$i] "isn´t in the office!" | Out-File -FilePath "C:\Temp\test.txt" -Append -encoding unicode

Without success.

Vivek Kumar Singh
  • 3,223
  • 1
  • 14
  • 27
Thomas Lang
  • 231
  • 1
  • 4
  • 12

2 Answers2

0

join the strings like

"User:", $arraylist_user[$i], "isn´t in the office!" -join " " | Out-File -FilePath "C:\Temp\test.txt" -Append -encoding unicode

"User:", $arraylist_user[$i], "isn´t in the office!" -join " " will join the three strings User:, $arraylist_user[$i] and isn´t in the office! and add a space between them.

Guenther Schmitz
  • 1,955
  • 1
  • 9
  • 23
0
echo "User: $($arraylist_user[$i]) isn´t in the office!" | Out-File -FilePath "C:\Temp\test.txt" -Append -encoding unicode
notjustme
  • 2,376
  • 2
  • 20
  • 27