#PSTip Decoding an HTML-encoded string

In my previous tip, I showed some of my favorite methods to convert date time string to the local time. In the same context of RSS feeds, I sometimes find the description text in the RSS feed is HTML-encoded. One example is the Azure service update feed.


$feed = 'http://azure.microsoft.com/en-us/updates/feed/'
$xml = Invoke-RestMethod -Uri $feed

Output from the above snippet differs based on what is the first item in the feed. When I want a readable text, this is not very helpful. So, here is one method I use to decode this string into something that is meaningful to me.

$xml | Select Title, @{Name='PublicationDate’;Expression={[DateTime]$_.PubDate}}, @{Name='Description’;Expression={([System.Web.HttpUtility]::HtmlDecode($_.Description)) -replace “<.*?>”,''}}

Share on:
comments powered by Disqus