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?
PowershellHTMLScripting Languages

Avatar of undefined
Last Comment
E=mc2
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
E=mc2
Flag of Canada image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
HTML
HTML

HTML (HyperText Markup Language) is the main markup language for creating web pages and other information to be displayed in a web browser, providing both the structure and content for what is sent from a web server through the use of tags. The current implementation of the HTML specification is HTML5.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo