惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

敖苛记

甜甜圈的数学:donut.c 是如何工作的 | 敖苛记 如何让 AI Agent 工具帮助你清理 C 盘,让 C 盘不再报红? | 敖苛记 如何安装 Claude Code 并用 cc-switch 配置国内大模型 | 敖苛记 如何在 Windows 安装 Git | 敖苛记 如何安装 Windows 的包管理器 scoop 并配置国内镜像 | 敖苛记 给 Deepseek 发 <think> 之后,它就串台了? | 敖苛记 敖苛记 敖苛记 如何使用 ollama 和 open-webui 搭建自己的本地 AI 助手 | 敖苛记 如何使用 archinstall 安装 Arch Linux | 敖苛记 如何使用 Ventoy 制作一个便捷的 Arch Linux to go | 敖苛记
如何处理 PowerShell 中文乱码问题 | 敖苛记
敖苛, i@kayro.cn · 2026-05-11 · via 敖苛记

设置一些命令默认使用UTF-8编码,解决 PowerShell 中的中文乱码问题,保证读写文件正确。

一次让ai写代码时
AI

除了这个文件有一些乱码行,没其他问题了

一些乱码行?没有呀?

AI

可能是编码问题

AI 修不好,我上网去搜

如果你在使用 PowerShell 时遇到了中文乱码问题,或者你的 Agent 工具不可以正常使用 PowerShell 读写中文文件,你可以尝试一下方法。

PS>

notepad $PROFILE

这将打开 PowerShell 的配置文件。如果文件不存在,Notepad 会提示你创建一个新的文件。

在打开的文件中,添加以下内容:

Microsoft.PowerShell_profile.ps1ps1
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['Get-Content:Encoding'] = 'UTF8'
$PSDefaultParameterValues['Set-Content:Encoding'] = 'UTF8'
$PSDefaultParameterValues['Add-Content:Encoding'] = 'UTF8'
$PSDefaultParameterValues['Out-File:Encoding'] = 'UTF8'
$PSDefaultParameterValues['Export-Csv:Encoding'] = 'UTF8'

title

代码说明

default

  • 设置 PowerShell 的输入编码为 UTF-8,这样 PowerShell 就可以正确地读取中文输入。
  • 设置 PowerShell 的输出编码为 UTF-8,这样 PowerShell 就可以正确地显示中文输出。
  • 设置 PowerShell 的默认输出编码为 UTF-8,这样 PowerShell 在输出到文件或管道时也会使用 UTF-8 编码。
  • 设置 Get-Content 命令的默认编码为 UTF-8,这样在使用 Get-Content 读取文件时会默认使用 UTF-8 编码。
  • 设置 Set-Content 命令的默认编码为 UTF-8,这样在使用 Set-Content 写入文件时会默认使用 UTF-8 编码。
  • 设置 Add-Content 命令的默认编码为 UTF-8,这样在使用 Add-Content 追加内容到文件时会默认使用 UTF-8 编码。
  • 设置 Out-File 命令的默认编码为 UTF-8,这样在使用 Out-File 输出到文件时会默认使用 UTF-8 编码。
  • 设置 Export-Csv 命令的默认编码为 UTF-8,这样在使用 Export-Csv 导出 CSV 文件时会默认使用 UTF-8 编码。

重启 PowerShell

保存文件后,关闭并重新打开 PowerShell。现在,你应该能够正确地处理中文输入和输出了。