最近在使用编程IDE环境时,IDE带的终端窗口中文显示乱码,找其原因是 PowerShell 默认没有使用 UTF-8。研究了下,解决方法如下:
编写PowerShell配置文件
- 以管理员身份打开PowerShell
- 创建配置文件
New-Item -ItemType File -Path $PROFILE -Force
- 编辑配置文件
notepad $PROFILE
- 配置文件写入
[System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8
重开一个PowerShell,OK!
如遇“因为在此系统上禁止运行脚本”
运行如下命令,重新打开即可
set-executionpolicy remotesigned