• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1748
  • Last Modified:

How to convert MHTML file to text file using PowerShell script

Is there any way to convert mhtml file to text file using powershell script?
0
SURESH0518
Asked:
SURESH0518
1 Solution
 
becraigCommented:
I guess the easiest I can think of is replacing all the html tags:
(gc file.mhtml) -replace "<.*?>" | out-file newfile.txt 

Open in new window

0
 
SURESH0518Author Commented:
but mhtml is Content-Transfer-Encoding: base64.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
gc file.mhtml | % {
  [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_))
} | out-file textfile.txt

Open in new window

or, removing the HTML Tags as shown above
gc file.mhtml | % {
  [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_)) `
    -replace "<.*?>"
} | out-file textfile.txt

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now