1

i'm trying to create a newline in a string to get a formated output of an array. the code:

$arr = @(
[PSCustomObject]@{Name = "David";  Article = "TShirt"; Size = "S"}
[PSCustomObject]@{Name = "Eduard"; Article = "extra laaaaaaaaaaaaaaaarge" + "`r`n" + "TShirt"; Size = "XXL"}
[PSCustomObject]@{Name = "John";  Article = "TShirt"; Size = "M"}
)

$arr

i expected this output:

Name   Article                         Size
----   -------                         ----
David  TShirt                          S   
Eduard extra laaaaaaaaaaaaaaaarge      XXL
       TShirt
David  TShirt                          M

but i get this:

Name   Article                            Size
----   -------                            ----
David  TShirt                             S   
Eduard extra laaaaaaaaaaaaaaaarge...      XXL 
David  TShirt                             M  

what is the trick?

3
  • for the last line, do $arr | Format-Table -Wrap Commented Feb 13, 2020 at 9:53
  • great. this is the solution. great thanks. how can i flag this answer as "solved"? Commented Feb 13, 2020 at 10:10
  • You couldn't accept, because it was a comment. I have now added it as answer so it can be accepted by clicking the faint checkmark icon next to it. Cheers! Commented Feb 13, 2020 at 10:13

1 Answer 1

1

The output is the default PowerShell way of truncating long lines in table format.

You can see the code does what you expect if you change the last line into

$arr | Format-Table -Wrap

Output on console:

Name   Article                            Size
----   -------                            ----
David  TShirt                             S   
Eduard extra laaaaaaaaaaaaaaaarge         XXL 
       TShirt                                 
John   TShirt                             M
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.