0

I have a variable called $Properties, it consists of 3 arrays (All seperated into three lines):

NTER 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"

I wanto flatten the $Properties arrays into a single string variable, that looks exactly as above example but with no arrays, so something like this:

NTER 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"

I've tried $Var = $Properties -join '' but this takes all three lines and creates a single line:

NTER 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"NTER 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"NTER 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"NTER 4, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"LA2 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"LA2 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"LA2 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"LA2 4, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"

I've also tried $Var = $Properties -join "$null" , still the same issue. Any ideas would be wonderfull. Thanks!

Am on Powershell 7.3 (Preview)

3
  • 2
    It's not clear what your expected output is and your $properties variables is not syntactically correct. Please edit your question. Commented Aug 25, 2022 at 4:27
  • 1
    Please add a minimal reproducible example. Commented Aug 25, 2022 at 8:10
  • My apologies for any confusion caused, I have not edited the question for clarity Commented Aug 25, 2022 at 16:32

1 Answer 1

1

If you want to join the strings array with a line break, you can use

  • "`r`n"(CRLF) for Windows style, or
  • "`n"(LF) for Linux style.

Use $Var = $Properties -join "`r`n" in the code

$Properties = @(
  'NTER 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"'
  'NTER 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"'
  'NTER 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"'
)
$Var = $Properties -join "`r`n"

It will generate

NTER 1, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 2, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
NTER 3, ShortD = "Start > Then Dump", LongD = "Procces is started, then all errors are dumped to a log file"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.