"Trim versions" to be aligned with the library version settings

john john Pter 505 Reputation points
2025-02-19T20:29:09.42+00:00

Inside the "Version history" documentation, it is mentioned about "Trim versions":-

Trim existing versions on site, library, or OneDrive - SharePoint in Microsoft 365 | Microsoft Learn

but seems this is not something aligned with the libraries settings, for example we can have 2 document libraries one with 150 versions limit and one with 80 versions limit. 

then we can run this trim script on the whole site or on a specific document library:-

New-SPOSiteFileVersionBatchDeleteJob -Identity $siteUrl -MajorVersionLimit 30 -MajorWithMinorVersionsLimit 30

so we are running one trim script for 2 libraries that have different version limits, but can we dynamically build a trim script which is aligned with each library settings? so it will set the limit = 150 for the first library and 80 for the second library? without having to create a script for each library separably?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,320 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 21,880 Reputation points Microsoft Vendor
    2025-02-20T05:14:52.7166667+00:00

    Hi @john john Pter,

    Thanks for reaching out to us. We are very pleased to assist you.

    Unfortunately, we have to execute separate scripts for each document library if they have different limits.

    The New-SPOSiteFileVersionBatchDeleteJob command needs to specify the document libraries that need to be trimmed versions, so if the document libraries have different limits, we would need different scripts.

    We realize that it would be tedious to run separate scripts for each document library, but this is the only way we can do it at this time. We apologize for any inconvenience this may cause.

    If you have any questions, please do not hesitate to contact me.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here. Your contribution will be highly appreciated.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.