[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2198
  • Last Modified:

Text truncated in message field powershell command

Hi,

I use powershell to pull a event from event log. the command ran successfully, but the message field got truncated. I want to view the whole message instead of just the first line, how to do this?

The powershell script I use is:
get-EventLog application -newest 2000 | where {$_.entryType -match "Error"} | where{$_.source -match "vmauthd"} | where{$_.timewritten -match $tdate} |format-wide -column 2 timewritten, message | Out-File -filepath c:\test.txt

The result looks like this


TimeWritten                          message                                                                              
7:29:25 PM  Cannot connect to VMX: E:\Virtual Machines\Virtual Machine\Virtual Machine.vmx...        


Thanks in advance for you help!
0
changjia
Asked:
changjia
  • 3
1 Solution
 
LearnctxEngineerCommented:
Try using format-table with the wrap switch instead of format-wide.
0
 
LearnctxEngineerCommented:
I suppose some code would have been handy :)

get-EventLog application -newest 2000 | where {$_.entryType -match "Error"} | where{$_.source -match "vmauthd"} | where{$_.timewritten -match $tdate} | format-table timewritten, message -wrap -autosize | Out-File -filepath c:\test.txt

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:

Or export to CSV, then you don't have to worry about trying to make the format-* cmdlets display things.

Chris
0
 
changjiaAuthor Commented:
Awesome. After I paste the long command into the powershell window, it errored out because the command is too long and it doesn't fit on one line.. How to resolve this?

Thanks
0
 
LearnctxEngineerCommented:
If you need to spread a command across multiple lines, use the tick `
For example.
Get-Process | `
  Sort Name | `
  Select Name

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now