# 指定需要转换的目录和文件扩展名 $directory = "I:\Git\HuanMengAdmin\admin-server\" $extension = "*.cs" # 修改为你需要的文件扩展名 # 获取指定目录下所有符合条件的文件 Get-ChildItem -Path $directory -Filter $extension -Recurse | ForEach-Object { $file = $_ # 读取文件内容并转换为 UTF-8 编码 $content = Get-Content $file.FullName -Raw [System.IO.File]::WriteAllText($file.FullName, $content, [System.Text.Encoding]::UTF8) }