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
  • 2,967
  • 1
  • 16
  • 24
Thomas Lang
  • 191
  • 1
  • 1
  • 10

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,882
  • 1
  • 8
  • 22
0
echo "User: $($arraylist_user[$i]) isn´t in the office!" | Out-File -FilePath "C:\Temp\test.txt" -Append -encoding unicode
notjustme
  • 2,296
  • 2
  • 22
  • 26