Link to home
Create AccountLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Using powershell to convert .txt file to .html

I would like to use a Powershell script to convert a text file to html
Can this be done?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

if you mean just to change the file extension? if yes, then simply use Rename-Item command to do it.

Rename-Item

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-item?view=powershell-7.1

if you mean to convert the text file content accordingly, then you need to provide at least some requirements on this.


Avatar of E=mc2

ASKER

$content = cat yourfile.txt -Raw
$title = 'My HTML'
$html = @"
<html>
<head><title>$title</title></head>
<body>
<pre>$content</pre>
</body>
</html>
"@
$html | Out-File 'file.html'
ASKER CERTIFIED SOLUTION
Avatar of E=mc2
E=mc2
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer