Overwrite
echo "Text to add" > C:\file.txt
Create/overwrite
Set-Content -Path C:\file.txt -Value "Text"
Create/Overwrite
"Text to add" | Set-Content C:\file.txt
Create/Overwrite
[System.IO.File]::WriteAllText("C:\file.txt", "Text")
Overwrite using .NET
echo.> C:\file.txt
Clear content
type NUL > file.txt
Create empty file or clear file
Last updated
Was this helpful?