Commands / Files

Set-Content

Overwrite a text file

beginner Files Aliases sc

Set-Content
 Set-Content -Path .\notes.txt -Value 'Hello'
Works on
WindowsLinuxmacOS
PowerShell
5.1 and later
Reference
Microsoft Learn: Set-Content

Careful: Set-Content replaces the whole file.

Writes new content and wipes the old. Use Add-Content to append. On Windows PowerShell 5.1 the default encoding is often not UTF-8. PowerShell 7 writes UTF-8.

Try this

Set-Content -Path .\notes.txt -Value 'Hello' -WhatIf

Coming from another shell

ShellWhat you might type
bash / zshecho 'Hello' > notes.txt
cmd.exeecho Hello> notes.txt

More in From bash and From cmd.

Related commands