header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Field Width in Output
Last Post 23 Aug 2008 12:16 AM by SynJunkie. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
07 Aug 2008 01:43 PM  

Hi again,

I have created a simple script to check through the event logs of a server for a specific event.  I know i will be able to use this on a list of severs which is fine, and I know i can output this to csv which is also fine.

 

Gwmi Win32_NTLogEvent -comp server01 -filter "Eventcode=20491" | ft -prop computername,message

 

My problem is that the message field in the event logs can sometimes contain quite a few lines of text.  in all my attempts to caoture the information i need i find that the output of the message field is limited and only displays the first 60 characters.  Is there a way to increase this because I need the entire contents of the message field?  i have tried using -auto and that does not seem to help.

I bet this is an easy one, but after a day of trying stuff and googling i'm stumped.

Any suggestions would be great.

Thanks

Lee

 

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
07 Aug 2008 09:02 PM  
There's a few ways to do this. One would be to use the -wrap parameter on format-table. Exporting to CSV or HTML would also do the trick if you'd like to see the data in those ways.

66# Gwmi Win32_NTLogEvent -filter "Eventcode=1000" | select -First 3 | ft computername
, message -wrap

computername                               message
------------                               -------
ATLLAPHROTTENBE                            Performance counters for the WmiApRpl (Wmi
                                           ApRpl) service were loaded successfully.
                                           The Record Data contains the new index val
                                           ues assigned
                                           to this service.

ATLLAPHROTTENBE                            Performance counters for the WmiApRpl (Wmi
                                           ApRpl) service were loaded successfully.
                                           The Record Data contains the new index val
                                           ues assigned
                                           to this service.

ATLLAPHROTTENBE                            Performance counters for the MSSQL$SQLEXPR
                                           ESS (SQL Server (SQLEXPRESS)) service were
                                            loaded successfully.
                                           The Record Data contains the new index val
                                           ues assigned
                                           to this service.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
08 Aug 2008 10:51 AM  

Hal

Thanks for the help. You were absolutely right, I could use the -wrap command or output to a CSV and this did fix the problem with the limitation. The problem then became that the message field in the events I am filtering for have got returns in which caused either a csv or log file (depending on what I output to) to wrap around and not display the whole field in a continuous line 9i do hope that makes sense).

The code I used following your suggestion was:


Gwmi Win32_NTLogEvent -comp srv01 -filter "Eventcode=20491" | select -prop computername,message | export-csv -Path c:\events.csv


Although I want to still find a solution to this problem using Powershell I was able to use Logparser in a FOR loop to achieve my aim. Encase anyone is interested the code for that was:

FOR /f %i in (c:\server.txt) do @LogParser.exe -i:EVT -o:CSV "SELECT computername,message FROM \\%i\application WHERE eventid= '20491'" >>c:\events.log

Again, thanks for the suggestion and keep up the great work on the podcast. I'm catching up but I'm on episode 14 at the moment so a little way to go yet. Each episode gets better and you guys really explain thing well.

Regards

Lee

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
08 Aug 2008 12:56 PM  
You could do this:
$events = Gwmi Win32_NTLogEvent -comp galmsrv01 -filter "Eventcode=20491" | select -prop computername,message
$events | foreach-object { $_.message = $_.message -replace "`n", " " } | export-csv file.csv


It could be done in one line but I split it for clarity.

Odd that logparser does not preserve the CRs...
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
21 Aug 2008 12:42 PM  

Hal

 

I'm still having difficulty with removing the CR's from the message field when extracting data from event logs.  I used the following to practice on my local eventlogs, but I just get a blank csv.

 

Gwmi Win32_NTLogEvent -comp . -filter "Eventcode=35" | select -prop computername,message | foreach-object { $_.message = $_.message -replace "`n", " " } | export-csv d:\test.csv

 

Do you have any other ideas how I might accomplish this using Powershell rather than LogParser?

Thanks

Lee

ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
21 Aug 2008 12:56 PM  

Try to change the foreach to:

... | foreach-object { $_.message = $_.message -replace "`n", " " ;  $_.message }

 

If it doesn't work try this:

Gwmi Win32_NTLogEvent -comp . -filter "Eventcode=35" | select computername,@{n="message";e={$_.message.replace("`n","")}} | export-csv d:\test.csv

 

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
22 Aug 2008 11:26 PM  
Thanks Shay, i'll give that a go.

Can you tell me what @ is an alias for please?
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
23 Aug 2008 12:16 AM  
hey dont worry about answering that, it was just covered in my CBT Nuggets Videos. @ creates a hash table to be used when creating custom columns.

Thanks anyway.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer