Decode Html Encoded Text

When migrating Html content from a CMS database or other sources you might find the Html as an Html encoded string.

Example:

<p><strong>Some Text</strong></p>

But you want to have the string look like this:

Some Text

Script

The following script is a simple PowerShell script to convert an exisiting file containing the Html encoded text and save the decoded string to a new output file.

param( [string]$InputFile, [string]$OutputFile)Add-Type -AssemblyName System.WebWrite-Output "Fetching $($InputFile)"$fileContent = Get-Content $InputFileWrite-Output "Converting"[System.Web.HttpUtility]::HtmlDecode($fileContent) | Out-File -FilePath $OutputFile -Encoding utf8 -Force

 

Usage

.Convert-ToHtml.ps1 -InputFile '.InputFile.txt' -OutputFile '.Output.html'

 

Enjoy!

 

%d Bloggern gefällt das: