Chris Topher Chris Topher - 4 years ago 250
PowerShell Question

output will not format correctly

I am having some problems writing to a text file with powershell using the correct format. I am pulling some windows event logs and saving the output to a text file. When I issue the following 2 commands

$event = get-winevent -filterhashtable @{logname='ForwardedEvents'; id=4688}

$event | format-list >> C:\scripts\file01.txt

I get something like this saved to the text file with a bunch of white space and the line broken up because it is too long:

New Process Name:

Is there anyway to make the output look like this instead:

New Process Name: C:\Windows\System32\SearchFilterHost.exe


Answer Source

If you're only interested in the message content of the event, don't pipe the entire event object through Format-List - output the Message property directly instead:

$evt.Message >> C:\scripts\file01.txt
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download