-1

I wanted to set specific column size. Below is the image-

enter image description here

Here I have set the width to be 150 & the command is-

Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" } | Select providername, timecreated, id, leveldisplayname, message | Format-Table | Out-String -Width 150

As you can see the Messages are getting trimmed and TimeCreated column has lot of extra width. How can I set custom width for each column so that I can reduce the size for TimeCreated column and increase it for Message column.

Cœur
  • 37,241
  • 25
  • 195
  • 267
S R
  • 657
  • 3
  • 10
  • 21
  • try using the `-autosize` parameter of `format-table` and remove the `out-string` part. more info on formatting output: http://technet.microsoft.com/en-us/library/dd347677.aspx – Paul Nov 04 '14 at 04:11
  • 1
    also using `-autosize` the last selected row might get truncated which in your example is the one you want to show fully, in the case autosize isnt making enough space you can use `-wrap` to show the full text for all columns – Paul Nov 04 '14 at 04:23
  • Thanks @Paul. Since I am using PowerShell Studio, I had to use Out-String so that the result can be displayed in TextBox. This worked for me- `Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" } | Select providername, timecreated, id, leveldisplayname, message | Format-Table -Wrap | Out-String -Width 120` Thanks – S R Nov 04 '14 at 04:59
  • @paul good work i should have done that in my answer and you need to make that yours – Matt Nov 04 '14 at 05:10
  • i have added it as answer – Paul Nov 04 '14 at 14:36

1 Answers1

0

Use the -wrap parameter of Format-Table to disable trimming like so:

Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" } | Select providername, timecreated, id, leveldisplayname, message | Format-Table -Wrap | Out-String -Width 120

to remove unneeded column spacing use the -Autosize parameter. Note that using -Autosize without -wrap will still shorten the last selected field if it's content is too long.

More info on Output Formatting using Format-Table:

Technet

Paul
  • 5,524
  • 1
  • 22
  • 39