I have a situation where a server is creating journal files (MJ00001-MJ000x) and I want to move all the files to a backup directory but need to keep the last 10 in there to get the archive.
I looked at robocopy and Powershell Move-Item but the problem is the date modified is always the current day as the server looks to them if they are in the directory (hence I can't use move keeping last 10 based on date modified).
I would prefer a powershell method that can look at the filename and move all except the 10 highest numbered file as I can put that into a script to stop the server service and then restart after move.
Example file structure below:
Located in C:\Folder
mainfile.ext
MJ00001.ext
MJ00002.ext
MJ00003.ext
through to MJ00257.ext
In this example I want to move MJ0001.ext - MJ00247.ext to D:\Other_Folder\
Note that I want to keep the mainfile.ext in the directory and just the highest named MJ files.
Can anyone please help?