通过以下命令查询当前 PowerShell 版本:
$PSVersionTable
首先需要安装 .NET Framework 4.5.2 或更高版本:https://dotnet.microsoft.com/en-us/download/dotnet-framework
然后下载安装 PowerShell 5.1:https://www.microsoft.com/en-us/download/details.aspx?id=54616
(内含 Windows 7 SP1、Windows Server 2008 R2 SP1、Windows 8.1、Windows Server 2012 R2 版本的升级安装包)
另一个更友好的下载地址:https://docs.microsoft.com/zh-cn/powershell/scripting/windows-powershell/wmf/setup/install-configure
如果在执行包含中文内容的脚本时不显示中文,或 Write-Output 中文时出错,如下图:
out-lineoutput : The Win32 internal error "A device attached to the system is not functioning" 0x1F occurred while writing to the console output buffer at the current cursor position. Contact Microsoft Customer Support Services.
+ CategoryInfo : WriteError: (:) [out-lineoutput], HostException
+ FullyQualifiedErrorId : WriteConsole,Microsoft.PowerShell.Commands.OutLineOutputCommand
解决方案:
1、在标题栏中点击右键,选择“属性”:
2、切换到字体选项卡,将原有默认点阵字体切换为上方字体:
3、点击确定即可正常使用。
参考:https://blog.51cto.com/jameszhan/2642202