首页 > 解决方案 > 如何在 Powershell 中管理 Unicode 字符

问题描述

我创建了一个执行外部命令的 powershell 脚本。

$filenames = command.exe $remoteFolder

此命令返回文件名列表,但在 Unicode 中,文件名随后存储在输出 CSV 文件中

"$remoteFolder;$filename" >> $exportFile

不幸的是,输出文件没有正确显示重音字母

fileà.txt

让重音字母显示正确的最佳方法是什么?

谢谢。

标签: powershellunicode

解决方案


>>在向其附加 utf16/unicode 字符之前不检查输出文件的编码,因此它可能会混合不同的编码。我会改为通过管道添加内容。该文件首先必须是 utf8 或 utf16。输出 unicode 字符的外部命令也可能存在问题。了解 unicode 字符和外部命令是什么会很有帮助。

"$remoteFolder;$filename" | add-content $exportFile

推荐阅读