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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Empty/delete OneDrive ...
Power Automate
Unanswered

Empty/delete OneDrive (business) recycle bin automatically?

(0) ShareShare
ReportReport
Posted on by 13

Trying to find a way to empty the recycle been more frequently then the 30 days. Been looking in the below thread but cant really figure out how to get it to completely empty it. All steps is not fully visible and im not an engineer myself.

There is a delete POST in the bottom of the thread and cant figure out how to use that.

Any guidance? 

https://powerusers.microsoft.com/t5/Building-Flows/Use-Power-Automate-to-permanently-delete-files-from-a-folder-or/m-p/1825071/highlight/true#M201308

Categories:
I have the same question (0)
  • Rhiassuring Profile Picture
    8,692 Moderator on at

    Hi there, 

     

    Which part are you having problems with in that post? Can you show what you've configured so far, and where you are running into issues?

    🐟 I imagine you'll trigger on a Schedule ... every 5 days? 15 days? Whatever you need.
    🐟 You'll initialize your OneDrive URL in a variable.
    🐟 Then, you'll want to "Get Items" first from your Recycle Bin. That'll help you identify what needs to be deleted (if anything). 
    🐟 Next, use the HTTP action, for the "GET". Where he has the variable, instead, you'll just point at your Dynamic Content from "Get Items" for the FileName w/ Extension. It'll turn into an Apply To Each, which means it'll loop through each item from the "Get Items".
    🐟 Then you'll do the HTTP with the "DELETE" - but where "body()" is, you'll point it at the output from the "GET" (which should be the ID.) 

     

    The flow will loop through until each item is gone.

     

  • AEES Profile Picture
    13 on at

    Thanks, i get the concept but fail on the details. What exactly to input where?

    AEES_1-1673294289989.png

    AEES_2-1673294317326.png

     

     

  • Rhiassuring Profile Picture
    8,692 Moderator on at

    I built it out and found a a cleaner way to do it:

     

    Rhiassuring_0-1673675749431.png


    File attached.

     

  • AEES Profile Picture
    13 on at

    Cool, thanks! Will try and test it during week 🙂

  • AEES Profile Picture
    13 on at

    Tested it and its working, thanks for great support @Rhiassuring!

  • pcamida Profile Picture
    9 on at

    Thanks for the solution! Can someone share the whole flow/code to copy-paste? I want to delete all items, empty recycle bin without exception. I don't know how to use your attached file. Thank you very much!

  • nicktalsma Profile Picture
    38 on at

    You download and import the zip file.  

     

    But here is the JSON:

     

    {
        "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"
                                        }
                                    }
                                },
                                "Author": {
                                    "type""object",
                                    "properties": {
                                        "__deferred": {
                                            "type""object",
                                            "properties": {
                                                "uri": {
                                                    "type""string"
                                                }
                                            }
                                        }
                                    }
                                },
                                "DeletedBy": {
                                    "type""object",
                                    "properties": {
                                        "__deferred": {
                                            "type""object",
                                            "properties": {
                                                "uri": {
                                                    "type""string"
                                                }
                                            }
                                        }
                                    }
                                },
                                "AuthorEmail": {
                                    "type""string"
                                },
                                "AuthorName": {
                                    "type""string"
                                },
                                "DeletedByEmail": {
                                    "type""string"
                                },
                                "DeletedByName": {
                                    "type""string"
                                },
                                "DeletedDate": {
                                    "type""string"
                                },
                                "DeletedDateLocalFormatted": {
                                    "type""string"
                                },
                                "DirName": {
                                    "type""string"
                                },
                                "DirNamePath": {
                                    "type""object",
                                    "properties": {
                                        "__metadata": {
                                            "type""object",
                                            "properties": {
                                                "type": {
                                                    "type""string"
                                                }
                                            }
                                        },
                                        "DecodedUrl": {
                                            "type""string"
                                        }
                                    }
                                },
                                "Id": {
                                    "type""string"
                                },
                                "ItemState": {
                                    "type""integer"
                                },
                                "ItemType": {
                                    "type""integer"
                                },
                                "LeafName": {
                                    "type""string"
                                },
                                "LeafNamePath": {
                                    "type""object",
                                    "properties": {
                                        "__metadata": {
                                            "type""object",
                                            "properties": {
                                                "type": {
                                                    "type""string"
                                                }
                                            }
                                        },
                                        "DecodedUrl": {
                                            "type""string"
                                        }
                                    }
                                },
                                "Size": {
                                    "type""string"
                                },
                                "Title": {
                                    "type""string"
                                }
                            },
                            "required": [
                                "__metadata",
                                "Author",
                                "DeletedBy",
                                "AuthorEmail",
                                "AuthorName",
                                "DeletedByEmail",
                                "DeletedByName",
                                "DeletedDate",
                                "DeletedDateLocalFormatted",
                                "DirName",
                                "DirNamePath",
                                "Id",
                                "ItemState",
                                "ItemType",
                                "LeafName",
                                "LeafNamePath",
                                "Size",
                                "Title"
                            ]
                        }
                    }
                }
            }
        }
    }
  • fcfgts Profile Picture
    2 on at

    IMG_20230905_005902.jpg

    yeah thanks it worked at first, but at the next run I got this error:

     

    Unable to process template language expressions for action 'Apply_to_each' at line '0' and column '0': 'The number of foreach items limit exceeded for action 'Apply_to_each': maximum '5000' and actual '11612'.'.

     

    So there's 10,000+ trashed files in my onedrive account and I got that 5000 limitation, how to make the script delete the first 5000 and then the next 5000 in the next schedule? @Rhiassuring  thanks

  • Paul_ZA_NZ Profile Picture
    2 on at

     Hi sorry to bump an old topic, but this the closest I could find to a similar situation I am trying to achieve.

    I have a 365 for developers account, in which several onedrive accounts automatically add & delete data. - My only issue is that the Recycle bin isn't able to be emptied, and I have to log in, and do it manually -  if I don't, the accounts eventually get full and it is a little bit of a hindrance.

    This is the first time I am attempting to use PowerAutomate - I eventually will find my way, I just need some firm guidance.  I was thinking of running a command to automatically empty the recycle bin once per day - this should sort all the issues I have been having.


    I have tried using Rhea's script, and edited the relevant info to reflect my own Onedrive account, using Wordpad. I also changed the frequency from 3 days, to one day, I am then able to import file into power automate, but I cannot add a connection to OneDrive, and once I exist the PowerAutomate page, it doesn't show up again.

    Will wait for a response.

    Thanks so much in advance.

  • Keenum Profile Picture
    2 on at

    I had to go into my Connections and make sure my Sharepoint connection was fixed before I was able to run this successfully. Make sure all of your connections look good.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 594

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 281 Super User 2026 Season 1

Last 30 days Overall leaderboard