PowerShell 修改编码为 UTF-8 教程

查看当前编码

打开 PowerShell,输入

复制代码
[Console]::OutputEncoding

如果 CodePage 显示 936:说明当前是 GBK 编码

如果 CodePage 显示 65001:说明当前是 UTF-8 编码

临时修改

复制代码
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

永久修改

检查配置文件是否存在

复制代码
Test-Path $PROFILE

返回 True:文件存在

返回 False:文件不存在

创建配置文件(如果不存在)

复制代码
New-Item -Path $PROFILE -Type File -Force

查看配置文件位置

这句命令会打印出当前正在使用的那个配置文件的绝对路径

复制代码
$PROFILE

编辑配置文件

我使用 VScode,可以输入

复制代码
code $PROFILE

也可以找到文件位置,手动打开

写入配置代码

复制代码
# 设置输出编码为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# 设置输入编码为 UTF-8 
[Console]::InputEncoding = [System.Text.Encoding]::UTF8

重新打开 PowerShell 试试

复制代码
[Console]::OutputEncoding
相关推荐
console.log('npc')1 天前
Windows 11 安装 WSL2 + Ubuntu + Docker + Codex + Sub2API 教学
windows·docker·powershell·ubantu·codex
CV工程师(Ctrl)2 天前
Codex 在 Windows 中文路径执行bash命令编码问题复盘
powershell·codex
vortex54 天前
PowerShell 的命令补全方案: PSReadLine + PSCompletions + argc + Carapace
windows·powershell
深念Y15 天前
踩坑实录:把 Windows 默认 PowerShell 换成 7.x 到底有多坑?一条龙解决指南
windows·乱码·bug·控制台·powershell·管道·流式
IOT那些事儿23 天前
Windows PowerShell配置Qt5编译运行环境
windows·powershell·qt5
今夕资源网25 天前
powershell工具包 安装升级脚本并设置UTF-8 环境快捷方式创建 将powershell的编码默认改为UTF-8
开发语言·utf-8·powershell·utf-8编码·powershell7·powershell5·设置utf-8编码
fengyehongWorld1 个月前
Powershell 注册.dll类库到系统
powershell
就叫年华吧丶1 个月前
Git Bash、CMD 与 PowerShell 的区别详解
linux·git·命令行·powershell·cmd·gitbash
Soari1 个月前
Ziggo-CaaS-Switch软件配置教程
bash·powershell·tsn 交换机
LAM LAB1 个月前
【shell】win10 Powershell字体美化
powershell