web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Flow Deleting old Vers...
Power Automate
Answered

Flow Deleting old Versions on Sharepoint

(0) ShareShare
ReportReport
Posted on by

Good day,

 

I have to run a flow each day to update datas. When I run them a new Version of the document is always created.

I have around 24 GB of Datas, Each File multiplied by 100. 
So I have 1,4 TB of data and my Storage is full.

 

MY QUESTION: Does anybody know how to delete all old Versions of a File in Sharepoint as it is not possible to set Versions to a lower Number then 100

 

Thanks


BRGDS
Jan Held

Categories:
I have the same question (0)
  • Verified answer
    mardex Profile Picture
    on at

    I mean delete with FLOW!!!! not manually


    @mardex wrote:

    Good day,

     

    I have to run a flow each day to update datas. When I run them a new Version of the document is always created.

    I have around 24 GB of Datas, Each File multiplied by 100. 
    So I have 1,4 TB of data and my Storage is full.

     

    MY QUESTION: Does anybody know how to delete all old Versions of a File in Sharepoint as it is not possible to set Versions to a lower Number then 100

     

    Thanks


    BRGDS
    Jan Held


     

  • ScottShearer Profile Picture
    25,270 Most Valuable Professional on at

    @mardex 

    To delete old versions, you'll need to use the SharePoint HTTP action and call a SharePoint web service.  I can't provide the specifics, but that's the route you'll need to go.  Another way to approach this might be to create a new document (based on the old document including metadata) and delete the old one rather than updating the existing documents in your Flow.

  • mardex Profile Picture
    on at

    thanks, I expected this. So it will be a hell of work for me as a non professional Smiley Sad


    @ScottShearer wrote:

    @mardex 

    To delete old versions, you'll need to use the SharePoint HTTP action and call a SharePoint web service.  I can't provide the specifics, but that's the route you'll need to go.  Another way to approach this might be to create a new document (based on the old document including metadata) and delete the old one rather than updating the existing documents in your Flow.


     

  • Verified answer
    v-litu-msft Profile Picture
    on at

    Hi @mardex,

     

    Please refer to the following steps to delete the old versions of each file in the SharePoint library:

     

    Step 1: Add Get files(properties only) action to get files in the list.

    Step 2: Add Send an HTTP request to SharePoint

    Method: GET
    Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions

    Annotation 2019-08-29 150852.pngStep 3: Parse JSON, put the body of the previous action into the Content of Parse JSON action, then click the button "Use sample payload" to generate schema to paste the following schema:

    {
    "type": "object",
    "properties": {
    "d": {
    "type": "object",
    "properties": {
    "results": {
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "__metadata": {
    "type": "object",
    "properties": {
    "id": {
    "type": "string"
    },
    "uri": {
    "type": "string"
    },
    "type": {
    "type": "string"
    }
    }
    },
    "CreatedBy": {
    "type": "object",
    "properties": {
    "__deferred": {
    "type": "object",
    "properties": {
    "uri": {
    "type": "string"
    }
    }
    }
    }
    },
    "CheckInComment": {
    "type": "string"
    },
    "Created": {
    "type": "string"
    },
    "ID": {
    "type": "integer"
    },
    "IsCurrentVersion": {
    "type": "boolean"
    },
    "Length": {
    "type": "string"
    },
    "Size": {
    "type": "integer"
    },
    "Url": {
    "type": "string"
    },
    "VersionLabel": {
    "type": "string"
    }
    },
    "required": [
    "__metadata",
    "CreatedBy",
    "CheckInComment",
    "Created",
    "ID",
    "IsCurrentVersion",
    "Length",
    "Size",
    "Url",
    "VersionLabel"
    ]
    }
    }
    }
    }
    }
    }

     

    Annotation 2019-08-29 151226.png

    Step 4: Create the other Send an Http request to SharePoint:

    Method: DELETE
    Uri: _api/web/GetFolderByServerRelativeUrl('Dynamic content of Folder Path')/Files('Dynamic content of File name with extension')/Versions(ID from the previous action)

    Please have a try, I hope it can help you.

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • cg55 Profile Picture
    2 on at

    Hi there,

     

    Is it possible to set this up to on-demand remove all of the previous versions in a selected folder only, rather than daily automation for the whole library?

     

    I would like to be able to select a project folder within a library once that project is completed, delete all the previous versions, keeping only the final files and then mark all files in that folder as read only so that no new versions are created if people then go and look at the files as reference for another project.

     

    Many thanks

     

    Chris

    Many thanks

  • sscarcella Profile Picture
    239 on at

    This is exactly what I am looking for, do you have more details you can provide on this or a video you can point me to on how to create this flow?  When I create the Uri there is no dynamic content to choose from.  It seems some steps are missing.  What trigger do you use?  I tried using scheduled once a week.  Also is there a way to keep say 5 versions?

  • pityman Profile Picture
    115 on at

    This is what i want to do. but the things is I will exceed the 500 Apply to each limitation as I have a lot of files in a folder + subfolders. is there anyone can help?

  • Hellcat Profile Picture
    8 on at

    PnP PowerShell should become your fried if it is not already.  There a ton of good resources available to answer you requirements or get you headed in the right direction.  Salaudeen Rajack at https://www.sharepointdiary.com/ is an outstanding resource.  He has been very generous in sharing many PnP scripts to accomplish a task, and all of them can be adjusted to do more or less, or become very granular.

     

    Hop over to https://www.sharepointdiary.com/ and search for "delete versions" or Google it.  I've modified the available scripts for date ranges, file types, selection by user, operations on specific folders and more.

     

    First thing I did was to set max versions to the minimum of 100 in the SharePoint admin center.  100 is as low as they allow you to go.  It would be fantastic if MS would reduce the number to something more reasonable.

     

    Next thing was to delete all version of any image file (JPG, TIFF etc.)  There is a script at https://www.sharepointdiary.com/ to delete all versions.  Just modify it for the file type or file extension you want to delete all versions for.

     

    Next verify you users are okay to retain 1, 2, 5, 10 versions of an MS Office file type or extension, then modify and run the available script to delete all but "x" number of versions for that file type.  I got rid of many PPTX, DOCX and XLSX version.  Some of the PPTX and DOCX are huge files.

     

    Use use an image size reducing app to shrink your pictures, then go back and delete the picture versions.  Irfanview is a great free tool for shrinking images.

     

    Have your users reduce the size their PowerPoint files.  The go back and delete old versions again with PS PnP.

     

    Once you have your PS scripts tuned they way you need them, schedule them to run daily/weekly/monthly.

     

    SharePoint Flows are good but can be a challenge to get right.  For me, PowerShell scripting and automation is the way to go.  Much more intuitive and flexible.  There isn't too much you cannot accomplish with PS.

     

    Oh yeah, keep your Recycle Bin and Secondary Recycle Bin emptied on a schedule.  Yes, there is a PS script for that.

     

    I recovered 700+ GB by doing the things listed above, and significantly reduced my personal workload by automating with PS.

  • Hellcat Profile Picture
    8 on at

    I was asked where I found the max versions setting.

     

    Document library settings cog in upper-right > Library Settings > More Library settings > Versioning settings.

     

    Additional info can be found at SharePoint Online: Set Versioning Limit using PowerShell - SharePoint Diary

  • FF2 Profile Picture
    2 on at

    Hi I am running into an issue when following this example. When i create a library with a few files for testing it worked. When i revert back to the main task of deleting old versions from a library with subfolders i keep being told file error. Am i missing a trick with a setting when it is for a large library?

    Many thanks for you help

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard