Windows System.Net.WebClient中的powershell字符编码

Windows System.Net.WebClient中的powershell字符编码,windows,encoding,powershell,Windows,Encoding,Powershell,我正在运行以下命令: ([xml](new-object net.webclient).DownloadString( "http://blogs.msdn.com/powershell/rss.aspx" )).rss.channel.item | format-table title,link 其中一个RSS项目的输出包含以下奇怪的文本: You Don’t Have to Be An Administrator to Run Remote PowerShell Commands 因

我正在运行以下命令:

([xml](new-object net.webclient).DownloadString(
"http://blogs.msdn.com/powershell/rss.aspx"
)).rss.channel.item | format-table title,link
其中一个RSS项目的输出包含以下奇怪的文本:

You Don’t Have to Be An Administrator to Run Remote PowerShell Commands
因此,问题是:

  • 为什么角色混淆?撇号怎么了?为什么输出呈现为
    Don€™t
    当它应该只呈现为
    时,不
  • 如何在PowerShell标准输出中获得正确的字符

您需要设置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

这显示了powershell.Net交互的一个重要方面。我通常在.Net中编程,但未能将其视为要进行的.Net设置。