Keep x number of files and delete all others - Powershell
问题 I am trying to write a script that will look through a set of folders and keep only the last 10 files. The files in each folder could be created daily, weekly or monthly. I need the script to keep the 10 most recent copies regardless of the creation date or modified date. Using another post I created the script below that works but it doesnt keep 10 copies it keeps any file that isn't older than 10 days. $ftppath = "C:\Reports" Get-ChildItem $ftppath -recurse *_Report_*.zip -force|where {$_