Powershell character encoding from System.Net.WebClient

I run the following command:

([xml](new-object net.webclient).DownloadString(
"http://blogs.msdn.com/powershell/rss.aspx"
)).rss.channel.item | format-table title,link

The output for one of the RSS elements contains this strange text:

You Don’t Have to Be An Administrator to Run Remote PowerShell Commands

So the question is:

  • Why are the characters mixed? What happened to the apostrophe? Why is the output displayed as Don’t, when it should just display as Don't?
  • How to get the correct character in the standard release of PowerShell?
+5
source share
1 answer

You need to set the encoding property for the web client:

$wc = New-Object System.Net.WebClient
$wc.Encoding = [System.Text.Encoding]::UTF8
([xml]$wc.DownloadString( "http://blogs.msdn.com/powershell/rss.aspx" )).rss.channel.item | format-table title,link
+10
source

All Articles