Files and folders can accumulate over time and take up considerable space in the database or hard drives and end up slowing the computer considerably. However, deleting them manually isn't quite scalable. This is where PowerShell scripts can be of help. Execute the following script to delete all files older than a certain number of days, in a go.
Powershell script to delete files older than x days
Simply provide the folder pathname and the number of days from which the files have to be deleted. It is to be noted that the number of days must be negative. The following PowerShell script deletes files older than some days. You can use it to clean up old log files or temp folders. This example will use PowerShell to delete files older than 5 days.