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
相关推荐
IOT那些事儿2 天前
Windows PowerShell配置Qt5编译运行环境
windows·powershell·qt5
今夕资源网5 天前
powershell工具包 安装升级脚本并设置UTF-8 环境快捷方式创建 将powershell的编码默认改为UTF-8
开发语言·utf-8·powershell·utf-8编码·powershell7·powershell5·设置utf-8编码
fengyehongWorld10 天前
Powershell 注册.dll类库到系统
powershell
就叫年华吧丶10 天前
Git Bash、CMD 与 PowerShell 的区别详解
linux·git·命令行·powershell·cmd·gitbash
Soari15 天前
Ziggo-CaaS-Switch软件配置教程
bash·powershell·tsn 交换机
LAM LAB22 天前
【shell】win10 Powershell字体美化
powershell
humors22124 天前
AI工具合集,不定期更新
人工智能·windows·ai·工具·powershell·deepseek
fengyehongWorld1 个月前
Powershell 自动安装Excel自定义标签页,开启宏
powershell
西西弗Sisyphus1 个月前
PowerShell 配置为启动时自动激活 Conda 环境
conda·powershell
夫唯不争,故无尤也2 个月前
curl与Invoke-RestMethod核心区别
后端·fastapi·powershell·curl