Hi All.
I am PowerShell beginner , kindly ask you to help me with this non-trivial task.
I have full backup of the SharePoint Libraries including all documents revisions and versions.
For example:
LoDs TM1_Project and Engineering.8.0.xlsx
LoDs TM1_Project and Engineering.9.0.xlsx
LoDs TM1_Project and Engineering.10.0.xlsx
LoDs TM1_Project and Engineering.11.0.xlsx
The version value may be a 1, 2, 3 or 4 digit
How to select and copy only the latest version of each file?
It would be LoDs TM1_Project and Engineering.11.0.xlsx from example.
Sorting by date not applicable.
That’s actually a very non-trivial task. There are in fact more than enough examples out there.
What have you tried so far? We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
Assuming the latest version is the one with last write access you should be able to sort for the property LastWriteTime and pick the first or the last depending on the sorting order.
You have to search for duplicates. But it is up to you to decide what’s a valid duplicate. If your files follow a naming convention it should be easy.
Assumed your files names all look similar to the ones you posted you could split the file names on the first period and use the first part of the file name to group the result. Then you can pick only the newest file from each group and you’re done.
You may read more about
You should always read the complete help topic including the examples to learn how to use it.
The problem is that all files doesn’t locates in one folder and doesn’t have similar filenames.
The root directory contains thousands child folders. My example is just short view from one folder.
TM\Construсtion\Documents\Documents\Project Control\LIST OF PROJECTS 2021-2023.1706.0.xlsx (1705 files stays before )
TM\Construсtion\Documents\Documents\Project Control\Weekly Status Report of Key Projects_May_week_3.6.0.xlsx
And so on
At the end of the day you have to find a way to distinguish the different groups of versioned files. But it will be hard if they don’t have a common attribute you can rely on. You will have to find the unique or actually the unversal pattern what separates the actual file name from the version info. For the file names you poasted last it is the first period in the first file name and the last underline for the second file name.