Another file operations PowerShell script that was recently required. This time we had a folder that contains a large number of log files that were never rotated and took up a large amount of disk space. These logs are only used for troubleshooting issues if they occur and it is rarely required for us to go over log files older than 7 days, so why are we keeping the rest?
Here is an easy one liner to help!
Until next time!
Get-ChildItem –Path “E:\TEMP\Logs” –Recurse | Where-Object{$_.LastWriteTime –lt (Get-Date).AddDays(-7)} | Remove-Item
I tried to use your script and noticed that (getdate) should be (get-date). Thanks for the writeup. It made this super easy for me.
Thank you so much for your comment. I have updated the page with the correction!