cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mardex
Helper II
Helper II

Flow Deleting old Versions on Sharepoint

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
mardex
Helper II
Helper II

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


 

View solution in original post

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.

View solution in original post

8 REPLIES 8
mardex
Helper II
Helper II

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


 

@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.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

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.


 

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.

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

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
Helper III
Helper III

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
New Member

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.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (1,313)