Truncate log files with PowerShell
It is a very common task to truncate log files. You don't notice them and they reach the limit size always not in the appropriate time. And when this moment occurs, it's much better to have a quick solution to decrease the size of log files. But even much better to clean logs automatically on the schedule.
Some time ago I wrote about how to truncate log files in Linux operational systems. Now it's time to write about Windows.
In Windows there is a PowerShell cmdlet which you can use to clear contents of a file.
To clear contents of a single file:
Clear-Content C:\Temp\TestFile.txt
To clear contents of all files with the ".log" file extension:
Clear-Content -path * -filter *.log –force
"Clear-Content" only clears the contents of a file. It doesn’t delete the file. To delete the file use cmdlet Remove-Item:
Remove-Item C:\temp\file2delete.txt

A Hidden Visual Studio Trick: Execute Selected Code with double Ctrl+E
What do to with Zone.Identifier files after importing a WSL machine and copying data
Support for SharePoint Server 2019 ends on Tuesday, July 14, 2026