0

delete files older than x days using powershell

There may come a time when you want to delete files older than x days using powershell
You can do this via the following powershell code:

# Delete files older than x days 
Get-ChildItem '\\path\to\backup\folder' -Recurse | 
	Where {$_.creationtime -lt (Get-Date).AddDays(-7)} | 
		Remove-Item -Force

Subscribe to my feed either by E-mail or by RSS to receive updates as they happen.

Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.

Jason Edwards