看下https://til.secretgeek.net/powershell/out-file-encoding.html
-encoding ascii
-encoding default
-encoding oem
-encoding utf7
安装个notepad++(https://github.com/notepad-plus-plus/notepad-plus-plus),powershell执行下面代码后,用notepad++挨个打开去看,上面列出的4种是utf-8,我一般用-encoding ascii,尤其是.bat、.cmd、.vbs这些可执行文件,编码一定要显性指定-encoding ascii
"unknown" | out-file "c:\out-file-unknown.txt" -encoding unknown
"string" | out-file "c:\out-file-string.txt" -encoding string
"unicode" | out-file "c:\out-file-unicode.txt" -encoding unicode
"bigendianunicode" | out-file "c:\out-file-bigendianunicode.txt" -encoding bigendianunicode
"utf8" | out-file "c:\out-file-utf8.txt" -encoding utf8
"utf7" | out-file "c:\out-file-utf7.txt" -encoding utf7
"utf32" | out-file "c:\out-file-utf32.txt" -encoding utf32
"ascii" | out-file "c:\out-file-ascii.txt" -encoding ascii
"default" | out-file "c:\out-file-default.txt" -encoding default
"oem" | out-file "c:\out-file-oem.txt" -encoding oem
比如下面这种不可取
if ($Disk -match 'Disk%s+(?<DiskIdx>%d+)%s+(Online|Offline)%s+(?<Size>%d+)%s+GB%s+(?<Free>%d+)|磁盘%s+(?<DiskIdx>%d+)%s+(联机|脱机)%s+(?<Size>%d+)%s+GB%s+(?<Free>%d+)|Disk%s+(?<DiskIdx>%d+)%s+(Online|Offline)%s+(?<Size>%d+)%s+TB%s+(?<Free>%d+)|磁盘%s+(?<DiskIdx>%d+)%s+(联机|脱机)%s+(?<Size>%d+)%s+TB%s+(?<Free>%d+)')
{
}
应该是
if ($Disk -match 'Disk\s+(?<DiskIdx>\d+)\s+(Online|Offline)\s+(?<Size>\d+)\s+GB\s+(?<Free>\d+)|\u78c1\u76d8\s+(?<DiskIdx>\d+)\s+(\u8054\u673a|\u8131\u673a)\s+(?<Size>\d+)\s+GB\s+(?<Free>\d+)|Disk\s+(?<DiskIdx>\d+)\s+(Online|Offline)\s+(?<Size>\d+)\s+TB\s+(?<Free>\d+)|\u78c1\u76d8\s+(?<DiskIdx>\d+)\s+(\u8054\u673a|\u8131\u673a)\s+(?<Size>\d+)\s+TB\s+(?<Free>\d+)')
{
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。