powershell character encoding from System.Net.WebClient

青春壹個敷衍的年華 提交于 2020-01-13 10:22:09

问题


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?

回答1:


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


来源:https://stackoverflow.com/questions/2019251/powershell-character-encoding-from-system-net-webclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!