0

I currently have the code below:

Get-EventLog -LogName Application 
| Where-Object EventID -EQ 1033 
| Select-Object EventID, Message

So my question is how can I just show the first 10 characters of the Message?

Zini
  • 909
  • 7
  • 15
Laitosto
  • 55
  • 1
  • 5

2 Answers2

2

Use the substring method on your message property.

Get-EventLog -LogName Application | Select-Object EventID, @{Label='Message';Expression={$_.Message.Substring(0,10)}}
Taylor Gibb
  • 550
  • 3
  • 8
2

Just as a follow up:

Get-EventLog -LogName Application 
| Where-Object EventID -EQ 1033 
| Select-Object EventID, @{l="Message";e={$_.message.substring(0,10)}}
Jason Morgan
  • 1,055
  • 7
  • 10
  • That would only get the first 9 characters :) the first parameter of substring is what index to start at, while the second is how many characters you want. – Taylor Gibb Apr 07 '14 at 18:53