如何用power覆盖文件内容shell

how to overwrite file content with power shell

我是 Powershell 的新手。你如何在 powershell 中覆盖文件?现在写在下面的代码是附加的。我想用以下新信息完全覆盖文件。

$一些信息 |添加内容 $FileName

使用 Set-Content 而不是 Add-Content

Set-ContentAdd-Content的区别:
Add-Content=>追加
Set-Content=> 替换内容

参考:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-5.1

你也可以Out-File

'Some content' | Out-File -FilePath c:\windows\temp\file.log