Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, February 6, 2019 4:27 PM
I have a text file with 100 lines. I want to convert it to html. However when I do that the html file does not come line by line but
multiple lines are appearing on the same line. How can I resolve this?
I am trying the below, where filepath4 is the path of the text file and filepath4 is the path of the html file
Get-Content $filepath4 | Out-File $filepath4
Convertto-Html also does not give the desired results.
All replies (9)
Wednesday, February 6, 2019 5:13 PM ✅Answered
ConvertTo-Html cannot convert text files. It can only convert objects.
This will make separate lines of a text file in HTML:
$text = Get-Content $filename -Raw
"<pre>$text</pre>" | Out-File $fiename2
\(ツ)_/
Wednesday, February 6, 2019 4:29 PM
Have you tried ConvertTo-HTML cmdlet? All you're doing is opening a text file and creating a new text file with the same content.
/en-us/powershell/module/microsoft.powershell.utility/convertto-html?view=powershell-6
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Wednesday, February 6, 2019 4:32 PM
Yes Convertto-html also does not work.
Wednesday, February 6, 2019 4:42 PM
When I use converttohtml I get output like this:
| PSPath | PSParentPath | PSChildName | PSDrive | PSProvider | ReadCount | Length |
|---|---|---|---|---|---|---|
| C:\2019-02-06-success.txt | C:\ | 2019-02-06-success.txt | C | Microsoft.PowerShell.Core\FileSystem | 1 | 110 |
| C:\2019-02-06-success.txt | C:\ | 2019-02-06-success.txt | C | Microsoft.PowerShell.Core\FileSystem | 2 | 43 |
| C:\2019-02-06-success.txt | C:\ | 2019-02-06-success.txt | C | Microsoft.PowerShell.Core\FileSystem | 3 | 6 |
Wednesday, February 6, 2019 4:50 PM
What is the format of the text file you are parsing? That sounds to be the issue to me.
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Wednesday, February 6, 2019 4:57 PM
The format of the text file is like:
Backup Completed: Windows 10
Backup Completed: Servers
like this 100 lines.
Wednesday, February 6, 2019 11:59 PM
Tried this and getting the output in $filename2 as below:
*:
51
| *: | 53 |
| *: | 44 |
| *: | 60 |
| *: | 48 |
Thursday, February 7, 2019 12:05 AM
You copied the code incorrectly. Please copy it correctly.
\(ツ)_/
Thursday, February 7, 2019 12:14 AM
Yes, this is showing the output line by line in the html file. Thanks.