[{"data":1,"prerenderedAt":148},["ShallowReactive",2],{"content:\u002Fposts\u002F6c61ee2":3,"surround:\u002Fposts\u002F6c61ee2":142},{"id":4,"title":5,"body":6,"categories":118,"date":120,"description":121,"donation":122,"draft":123,"extension":124,"image":125,"meta":126,"navigation":122,"path":128,"permalink":128,"published":125,"readingTime":129,"recommend":125,"references":125,"seo":134,"sitemap":135,"stem":136,"tags":137,"type":139,"updated":140,"__hash__":141},"content\u002Fposts\u002F2026\u002Fpowershell_utf-8.md","如何处理 PowerShell 中文乱码问题",{"type":7,"value":8,"toc":111},"minimark",[9,36,39,44,48,51,55,67,104,108],[10,11,12,16,19,22,25,28,30,33],"chat",{},[13,14,15],"p",{},"{:一次让ai写代码时}",[13,17,18],{},"{AI}",[13,20,21],{},"除了这个文件有一些乱码行，没其他问题了",[13,23,24],{},"{.我}",[13,26,27],{},"一些乱码行？没有呀？",[13,29,18],{},[13,31,32],{},"可能是编码问题",[13,34,35],{},"{:AI 修不好，我上网去搜}",[13,37,38],{},"如果你在使用 PowerShell 时遇到了中文乱码问题，或者你的 Agent 工具不可以正常使用 PowerShell 读写中文文件，你可以尝试一下方法。",[40,41,43],"h2",{"id":42},"打开-powershell输入以下命令","打开 PowerShell，输入以下命令：",[45,46],"copy",{"code":47},"notepad $PROFILE",[13,49,50],{},"这将打开 PowerShell 的配置文件。如果文件不存在，Notepad 会提示你创建一个新的文件。",[40,52,54],{"id":53},"在打开的文件中添加以下内容","在打开的文件中，添加以下内容：",[56,57,64],"pre",{"className":58,"code":60,"filename":61,"language":62,"meta":63},[59],"language-ps1","[Console]::InputEncoding = [System.Text.Encoding]::UTF8\n[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n$OutputEncoding = [System.Text.Encoding]::UTF8\n$PSDefaultParameterValues['Get-Content:Encoding'] = 'UTF8'\n$PSDefaultParameterValues['Set-Content:Encoding'] = 'UTF8'\n$PSDefaultParameterValues['Add-Content:Encoding'] = 'UTF8'\n$PSDefaultParameterValues['Out-File:Encoding'] = 'UTF8'\n$PSDefaultParameterValues['Export-Csv:Encoding'] = 'UTF8'\n","Microsoft.PowerShell_profile.ps1","ps1","",[65,66,60],"code",{"__ignoreMap":63},[68,69,70,76],"folding",{},[71,72,73],"template",{"v-slot:title":63},[13,74,75],{},"代码说明",[77,78,79,83,86,89,92,95,98,101],"ul",{},[80,81,82],"li",{},"设置 PowerShell 的输入编码为 UTF-8，这样 PowerShell 就可以正确地读取中文输入。",[80,84,85],{},"设置 PowerShell 的输出编码为 UTF-8，这样 PowerShell 就可以正确地显示中文输出。",[80,87,88],{},"设置 PowerShell 的默认输出编码为 UTF-8，这样 PowerShell 在输出到文件或管道时也会使用 UTF-8 编码。",[80,90,91],{},"设置 Get-Content 命令的默认编码为 UTF-8，这样在使用 Get-Content 读取文件时会默认使用 UTF-8 编码。",[80,93,94],{},"设置 Set-Content 命令的默认编码为 UTF-8，这样在使用 Set-Content 写入文件时会默认使用 UTF-8 编码。",[80,96,97],{},"设置 Add-Content 命令的默认编码为 UTF-8，这样在使用 Add-Content 追加内容到文件时会默认使用 UTF-8 编码。",[80,99,100],{},"设置 Out-File 命令的默认编码为 UTF-8，这样在使用 Out-File 输出到文件时会默认使用 UTF-8 编码。",[80,102,103],{},"设置 Export-Csv 命令的默认编码为 UTF-8，这样在使用 Export-Csv 导出 CSV 文件时会默认使用 UTF-8 编码。",[40,105,107],{"id":106},"重启-powershell","重启 PowerShell",[13,109,110],{},"保存文件后，关闭并重新打开 PowerShell。现在，你应该能够正确地处理中文输入和输出了。",{"title":63,"searchDepth":112,"depth":112,"links":113},4,[114,116,117],{"id":42,"depth":115,"text":43},2,{"id":53,"depth":115,"text":54},{"id":106,"depth":115,"text":107},[119],"技术","2026-05-11 23:53:45","设置一些命令默认使用UTF-8编码，解决 PowerShell 中的中文乱码问题，保证读写文件正确。",true,false,"md",null,{"slots":127},{},"\u002Fposts\u002F6c61ee2",{"text":130,"minutes":131,"time":132,"words":133},"3 min read",2.295,137700,459,{"title":5,"description":121},{"loc":128},"posts\u002F2026\u002Fpowershell_utf-8",[138],"powershell","tech","2026-05-12 00:58:12","7fvU4T00z6g5vNqQPqDywIQpzLtNqwjOhN0nUeGJ6pQ",[143,125],{"title":144,"path":145,"stem":146,"date":147,"type":139,"children":-1},"Java 面向对象笔记：接口、抽象类、多态与重写","\u002Fposts\u002F132cbd8","posts\u002F2026\u002Fjava-oop","2026-04-24 00:44:30",1778519044586]