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

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
N
Netflix TechBlog - Medium
P
Privacy International News Feed
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
C
Cybersecurity and Infrastructure Security Agency CISA
The Register - Security
The Register - Security
P
Palo Alto Networks Blog
GbyAI
GbyAI
量子位
Simon Willison's Weblog
Simon Willison's Weblog
Cyberwarzone
Cyberwarzone
M
MIT News - Artificial intelligence
T
Threatpost
腾讯CDC
MyScale Blog
MyScale Blog
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
博客园 - 叶小钗
V
V2EX
美团技术团队
NISL@THU
NISL@THU
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
C
Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
爱范儿
爱范儿
G
Google Developers Blog
博客园 - Franky
P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
B
Blog
Spread Privacy
Spread Privacy
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Latest news
Latest news
The GitHub Blog
The GitHub Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
F
Full Disclosure
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
Scott Helme
Scott Helme
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs

敖苛记

甜甜圈的数学: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。现在,你应该能够正确地处理中文输入和输出了。