Share via


Formatting log file and export to html

Question

Sunday, August 20, 2017 1:41 AM

Hi guys,

i have a little problem formatting the below text file ( it's a log file ), when i open with notepad or try to ConvertTo-Html rows but lines are not formatted correctly, each row is next to each other without newline each '|'

When i open the file with wordpad format is right.

The target: create an html report with right forrmatting

THE TEXT FILE:

 | informazioni riga: 0x8d165e86fb819666 | TraceLevel: 0x1 | $module: gtob_backup_command_addon_vs_50064 | | errore 0xa100c8: Impossibile ottenere gli URI dell'archivio dalla posizione 'arl:/E08990EE-E5AA-4004-B033-B63DB0D486CE/B1E0EA83-D73D-4101-917D-02A1B802A500'. | informazioni riga: 0xb320396adfe3b54 | IsReturnCode: 0x1 | $module: disk_bundle_vs_50064 | | errore 0xa100c8: Impossibile ottenere gli URI dell'archivio dalla posizione 'arl:/E08990EE-E5AA-4004-B033-B63DB0D486CE/B1E0EA83-D73D-4101-917D-02A1B802A500'. | informazioni riga: 0xa0f87a51d6f9cc8e | IsReturnCode: 0x1 | $module: disk_bundle_vs_50064 | | errore 0x400280: Impossibile aprire la directory dei metadati. | informazioni riga: 0xa1d3981537c68781 | $module: disk_bundle_vs_50064 | | errore 0x40002e: Impossibile aprire la posizione di backup. | 

WHEN I OPEN IT WITH WORDPAD

SCRIPT:

$a = Get-Content C:\ProgramData\logs\2017-08-20-02-55-39*.log 

ConvertTo-Html -Body $a  | Out-File c:\report.html
&c:\report.html

All replies (14)

Friday, August 25, 2017 2:54 PM ✅Answered

This is the solution:

$a = (Get-Content C:\ProgramData\logs\2017-08-20-02-55-39*.log) -ireplace "\|","`r`n|"

Or this is another solution and works fine:

http://lifeofageekadmin.com/how-to-use-powershell-to-create-html-from-a-text-file/


Sunday, August 20, 2017 1:49 AM

Get-Content C:\ProgramData\logs\2017-08-20-02-55-39*.log |
    Out-String |
    ConvertTo-Html| 
    Out-File c:\report.html
& c:\report.html

In general, text output as HTML will not display correctly. "ConvertTo-Html" s intended to be used with objects.

\(ツ)_/


Sunday, August 20, 2017 1:53 AM

Here is another method"

Get-Content C:\ProgramData\logs\2017-08-20-02-55-39*.log |
    ForEach-Object{$_ += '<br/>'} |
    Out-File c:\report.html
& c:\report.html

\(ツ)_/


Sunday, August 20, 2017 2:14 AM

Using the first method the result is a page with this:


Sunday, August 20, 2017 2:17 AM

Using the first method the result is a page with this:

Like I posted.  You cannot convert text to HTML with that command

\(ツ)_/


Sunday, August 20, 2017 2:17 AM

Second method give me white page


Sunday, August 20, 2017 2:20 AM

You have other issues with your text file.

\(ツ)_/


Sunday, August 20, 2017 2:24 AM

mmm.. is a simply txt file, I tried to copy the content to a new file, the same thing, the second method does not work.


Sunday, August 20, 2017 2:28 AM

Sorry. Can't help you. Your log files are not in a known format for this.

I can take any log and change its extension to "htm" and it will display. It will not be formatted correctly. HTML cannot display line breaks.

\(ツ)_/


Sunday, August 20, 2017 2:32 AM

If I used formatting with select-string?
Or I could import each line into an array.
Once all the rows are separate I can import them into a right html table?

Can there be no method?


Friday, August 25, 2017 12:44 PM

Hi,

Was your issue resolved?

And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here. It will be greatly helpful to others who have the same question.

Appreciate for your feedback.

Best Regards,
Albert Ling

Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, August 31, 2017 10:54 AM

Hi,

Thanks for your posting here and sharing the resolution in the forum as it would be helpful to anyone who encounters similar issues.
If there is anything else we can do for you, please feel free to post in the forum.

Best Regards,
Albert Ling

Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, August 31, 2017 11:07 AM

Mark my post as answer if is good for you


Friday, September 1, 2017 5:53 AM

Hi,

You could mark your post as answer because you are the OP.

If there is anything else we can do for you, please feel free to post in the forum.

Best Regards,
Albert Ling

Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].