Show MenuHide Menu

Tag: SupportsShouldProcess

How to Identify and Remove Old Files With PowerShell

March 27, 2012

Today, I want to share a second PowerShell function, Remove-OldFiles, that shows how to identify and remove old files. Typically, you want such a function in order to keep log and temp folders clean from very old stuff.

Old files, what does that mean? The function investigates the LastWriteTime property from each file found and compares it to a given maximum age. By default, the function will delete all files with a lastwritetime that is over 90 days.

Disclaimer: I hope that the information in this post is valuable to you. Your use of the information contained in this post, however, is at your sole risk. All information on this post is provided “as is”, without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. Further, I shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.