Delete files from folder older than any days from PowerShell script
1 min readApr 30, 2021
This article is very simple and short, so the main goal is to delete (clean up) automatically any file from a specific folder older than any days wanted.
To achieve that, you can get the script from my GitHub repository:
For the script to work, you just have to define how many days you want to filter to delete files on the line below.
# Defines how many days the files can stay in the defined directory
$limit = (Get-Date).AddDays(-7)
You also need to paste the folder path where the files are located on the line below.
# Defines the destination directory to clean files
$path = "Put your folder path here"
And that’s it! Now we can automate this task easily.