2

I'm having a little issue with controlling output in ps. Here's the line of code in question;

$result|sort-object cn  | format-table -wrap -autosize 

If I append

| out-file $logfile

the last column of my output is truncated. Now I know that if I changed the width of my console session and run the script again, my output is fine, but there must be a better way of doing this? I also attempted to use add-content but I think I must be missing something as the expression isn't being evalulated correctly and I just get a series of references to system-object in my logfile.

2
  • You might try serverfault.com Commented Jun 24, 2009 at 3:55
  • I think it belongs here, since it's obviously an algorithm gone wrong instead of a server management problem. Commented Jun 24, 2009 at 6:04

2 Answers 2

4

You can use the -width parameter for the out-file cmdlet. You might try out-file -width 500 so nothing gets truncated.

Sign up to request clarification or add additional context in comments.

Comments

1

The best way I've determined so far is to use Out-String with a -Width longer than you expect the entire line to be:

$result | Format-Table -Autosize | Out-String -Width 4096

The only problem with the above is that it will pad the entire line with spaces. In order to get around that, add the -Stream switch and .Trim() each line:

$result | Format-Table -Autosize | Out-String -Width 4096 -Stream | %{ $_.Trim() }

This is also nice for piping the results to the clipboard with clip.exe (if I don't have the PSCX module installed with the Out-Clipboard command):

$result | Format-Table -Autosize | Out-String -Width 4096 -Stream | %{ $_.Trim() } | clip.exe

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.