| 用途 | 写入文本内容到文件 |
|---|---|
| 语法 | Set-Content <文件> <内容> [-Encoding UTF8];<对象> | Out-File <文件> |
| 差异 | Set-Content 按值写入;Out-File 按终端显示格式写入(含宽度限制) |
常用示例
常用示例
'ok' | Set-Content D:\Logs\status.txt -Encoding UTF8
Get-Process | Out-File D:\Logs\proc.txt -Encoding UTF8 -Width 3005.1 的 UTF8 会带 BOM;需要无 BOM 用 [IO.File]::WriteAllText 或 PS7 的 utf8NoBOM。