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 asDon't
? - How would I get the correct character in the PowerShell standard output?
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
精彩评论