Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell character encoding from System.Net.WebClient

I am running 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 items contains this weird text:

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

So, the question is:

  • Why the mix up in characters? What happened to the apostrophe? Why is the output rendered as Don’t when it should just render as Don't?
  • How would I get the correct character in the PowerShell standard output?
like image 593
elgrego Avatar asked Jan 07 '10 09:01

elgrego


1 Answers

You need to set the encoding property of the webclient:

$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
like image 179
Filburt Avatar answered Oct 13 '22 08:10

Filburt