Prune System Log Files

By James|05/20/2020|,

Introduction

Let's face it, logs are everywhere.  It seems like every piece of software creates log files these days.  Unfortunately, not every piece of software cleans up after itself or allows setting limits on the amount of logging to create and retain.  This can bring down a system if log file storage is not kept in check.

Resolution

The following PowerShell script will prune log files older than 60 days.  Modify the $DaysToKeep variable to change how many days worth of logs are kept.  At the bottom of the script, initiate the PruneLogFiles function with the folder(s) to prune.  Finally, use the Windows Task Scheduler to create a scheduled task.  Personally, I run the script weekly.  Enjoy!

 

Copyright 2011 - 2025 The Lazy IT Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram