0

I've written the code below which works fine apart from one of the variables is over 200 characters and goes onto the next line messing the layout up. Any suggestions on a better layout so if one of the variables is long, it still retains structure?

$WriteLog = $null $WriteLog = @() $WriteLog +="Here is some stuff: $stuff1" $WriteLog +="Here is some stuff: $stuff2" $WriteLog +="Here is some stuff: $stuff3" $WriteLog +="Here is some stuff: $stuff4" $WriteLog +="Here is some stuff: $stuff5" $WriteLog +="Here is some stuff: $stuff6" Out-File -InputObject $WriteLog -Append -NoClobber -FilePath "$env:SystemDrive\somestuff\somestuff.txt" 

Example output :

"Here is some stuff: stuff1" "Here is some stuff: stuff2" "Here is some stuff: Heres a lot of stuff stuff3, stuff3, stuff3, stuff3, stuff3, stuff3" "Here is some stuff: stuff4" "Here is some stuff: stuff5" "Here is some stuff: stuff6" 
1
  • As you can see ive updated the original question with a example. everything kind of lines up until "Heres a lot of stuff stuff3" and then it wraps onto the next line. I would like it to all justifie with stuff one and if it wraps onto the next line, again justify with stuff1. Hope i make a little more sence now. Thanks Commented Apr 12, 2012 at 19:15

2 Answers 2

1

I would use formatting if you are not sure (I hope I understand your problem). See

'{0,5} -f 5 #vs. '{0,5} -f 1115 

Then..

$WriteLog = $stuff1, $stuff2, $stuff3, $stuff4, $stuff5, $stuff6 | Foreach-Object { "Here is some stuff:{0,20}" -f $_ } $WriteLog = $WriteLog -join "`n" 
Sign up to request clarification or add additional context in comments.

Comments

1

Out-File has a -Width parameter that might help. Or can you format the long variable as a here string?

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.