0

After converting this table to a string, the columns are no longer aligned correctly. The data in the columns are, but the 3 columns themselves are not. Ideally I would want them aligned to the left. Is there any way to fix this? The reason I converted to a string is to eliminate unneeded space.

  (Get-EventLog system -computername $computernamehere -InstanceId 2147489657 -Newest 10 `
        | Format-Table `
            @{Name="Event ID";Expression = { $_.EventID }; Alignment="left" },
            @{Name="TimeWritten";Expression = { $_.TimeWritten }; Alignment="left" },
            @{Name="Machine Name";Expression = { $_.MachineName }; Alignment="left" } `
        | Out-String).Trim()
2
  • Why do you need to eliminate unneeded spaces? Is your end goal to have the output in a file? Commented Aug 31, 2015 at 9:40
  • I output the data on screen with other data, and everything is separated 1 line apart. This outputs with extra lines above and below, so I had to remove them by converting to a string. Commented Aug 31, 2015 at 13:28

1 Answer 1

2

I found the answer on my own. Just needed -Autosize. If anyone else has a better way, please let me know.

(Get-EventLog system -computername $computernamehere -InstanceId 2147489657 -Newest 10 `
    | Format-Table -Autosize `
        @{Name="Event ID";Expression = { $_.EventID }; Alignment="left" },
        @{Name="TimeWritten";Expression = { $_.TimeWritten }; Alignment="left" },
        @{Name="Machine Name";Expression = { $_.MachineName }; Alignment="left" } `
    | Out-String).Trim()
Sign up to request clarification or add additional context in comments.

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.