OneDrive for Business: Empty Recycle Bin using PowerShell

Requirement: Empty recycle bin in OneDrive for Business using PowerShell.

How to Empty the OneDrive Recycle Bin?

When you delete a file or folder from Microsoft OneDrive for Business, it goes to the first stage, “Recycle Bin”. If you delete it from the first-stage recycle bin, the deleted file or folder goes to the second-stage recycle bin. Deleted OneDrive files stay in the recycle bin until they’re permanently removed in 93 days automatically. However, the recycle bin can fill up over time, taking up storage space. You may have to remove them from the recycle bin within this time frame to free up storage space.

You can empty the “Recycle bin” in the OneDrive Site to reclaim storage space. Here’s how to empty your OneDrive’s Recycle bin:

  1. Log in to your OneDrive site, and click the “Recycle bin” link from the left navigation. (Visit https://www.office.com in the web browser, sign in with your user account and password, and click on the OneDrive icon from the waffle menu in the upper left of your screen)
  2. Now, you can see all the files and folders that were deleted in a descending list based on the date when they were removed. Select and restore any file/folder if needed.
  3. To empty your Recycle bin, tap the “Empty recycle bin” button on the top and confirm the prompt that tells you that it will delete all the items that are found in the Recycle bin, by pressing “Yes”.empty recycle bin onedrive for business powershell
  4. Once all files and folders are deleted from the End-User recycle bin, wait for some time and click on the “Second-Stage” Recycle bin.onedrive for business empty recycle bin powershell
  5. Again, click on “Empty Recycle Bin” in the second-stage recycle bin to remove files permanently and empty your OneDrive for Business Site’s recycle bin.onedrive for business recycle bin powershell
Important: Be sure you don’t need any files or folders in the recycle bin before you delete them permanently!

You can also access the OneDrive recycle bin from the OneDrive sync client in the system tray area on your desktop / PC!

open onedrive recycle bin

How to Empty OneDrive Recycle Bin from the Android or IOS App?

To empty the OneDrive recycle bin from the Android or iOS app, you can use the following steps:

  1. Open the OneDrive app on your Android or iOS device.
  2. Tap the “Me” icon at the bottom right of your screen.
    clear onedrive recycle bin android
  3. Select the account you’re using, and then tap Recycle Bin.
    empty onedrive recyle bin from OneDrive app
  4. In the Recycle Bin view, select the files you want to delete.
  5. Tap Delete to remove the files permanently.
  6. If you want to empty the entire Recycle Bin at once, tap “Delete All” in the top-right corner.
    empty recycle bin in OneDrive

It is important to note that once you empty the recycle bin, the deleted items are permanently deleted and cannot be restored. Therefore, it is recommended to double-check the items in the recycle bin before emptying it.

PowerShell to Empty Recycle Bin in OneDrive for Business Site

Let’s empty the OneDrive for Business recycle bin using PnP PowerShell:

#Set Parameters
$OneDriveSiteURL="https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com/"

#Get Credentials to connect
$Cred = Get-Credential
 
#Connect to OneDrive for Business Site
Connect-PnPOnline $OneDriveSiteURL -Credentials $Cred

#empty recycle bin onedrive for business powershell
Clear-PnPRecycleBinItem -All -force

When you have more than 5000 items in your recycle bin, both the UI method and PowerShell above may fail with the “Threshold exceeded” error message. So, Here is how to clear recycle bin items in batches:

#empty first stage recycle bin in onedrive for business site
Get-PnPRecycleBinItem -FirstStage -RowLimit 5000  | Clear-PnpRecycleBinItem -Force

#PowerShell to empty 2nd Stage recycle bin in onedrive for business
Get-PnPRecycleBinItem -SecondStage -RowLimit 5000  | Clear-PnpRecycleBinItem -Force

However, You have to run the above script multiple times based on the number of items in the recycle bin. Let’s place it inside a while loop:

#Config Variables
$SiteURL =  "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"

#Connect to Tenant Admin Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get recycle bin items in batches and delete them permanently
While( (Get-PnPRecycleBinItem -RowLimit 500) -ne $null)
{
    Get-PnPRecycleBinItem -RowLimit 500 | Clear-PnPRecycleBinItem -Force
}

Empty Recycle Bin for All OneDrive for Business Sites using PowerShell

How about clearing recycle bins for all OneDrive sites in the Office 365 tenant? Well, Here is the PowerShell script:

#Set Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"

#Get Credentials to connect
$Cred = Get-Credential
 
#Connect to Tenant Admin Site
Connect-PnPOnline $AdminSiteURL -Credentials $Cred
 
#Get All OneDrive for Business Sites
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"

#Loop through each site
ForEach($Site in $OneDriveSites)
{ 
    #Connect to OneDrive for Business Site
    Connect-PnPOnline $Site.URL -Credentials $Cred
    Write-Host -f Yellow "Processing Site: "$Site.URL
 
    #empty recycle bin onedrive for business powershell
    Clear-PnPRecycleBinItem -All -force    
}

A similar script works for SharePoint Online as well! How to Empty Recycle Bin in SharePoint Online using PowerShell?

In conclusion, there are two ways to empty the recycle bin in OneDrive for Business, using the web interface or the PowerShell. It’s important to note that once the recycle bin is emptied from both stages of the recycle bin, the files and folders will be permanently deleted and cannot be recovered, so it is recommended to be cautious when emptying the recycle bin.

How to access the OneDrive recycle bin?

To access the OneDrive Recycle Bin, follow these steps: 1). Go to the Office.com website and sign in with your Microsoft/Work account. 2). In the app launcher, click on OneDrive App. 3). From the OneDrive site, Under the left navigation pane, click on the “Recycle bin” link. Here, you can restore or permanently delete the files you’ve removed.

Does the second stage recycle bin count against storage?

Yes, the second stage recycle bin in OneDrive counts against your storage. Both the first stage and second stage recycle bins in SharePoint and OneDrive are temporary storage locations for deleted files and folders, and it does affect your total OneDrive storage quota.

What happens if I delete files from the OneDrive recycle bin?

Deleted items go into the OneDrive recycle bin, where they stay until they’re automatically removed after 93 days. When you delete files from both stages of the OneDrive recycle bin, or they are deleted after 93 days automatically – they are permanently deleted. They cannot be restored unless you have a backup mechanism/retention policy/approach Microsoft support within 14 days.

How do I empty the second-stage recycle bin in OneDrive?

To empty your Second-Stage Recycle Bin in OneDrive, first open up your OneDrive site >> Click on “Recycle bin” from the left navigation menu. On the recycle bin page, scroll to the bottom of the page and click on the “Second-Stage Recycle Bin” link. From there, you can click on the “Empty Recycle Bin” link to empty the Second-Stage Recycle Bin in OneDrive.

Can you recover deleted files after emptying the recycle bin in OneDrive?

Yes, it is possible to recover deleted files after emptying the recycle bin in OneDrive. However, it is important to act quickly and follow the right steps. There are several methods you can try, such as using the retention policy, using 3rd party backup solutions like Carbonite, or contact Microsoft support for assistance.

How long are files kept in the OneDrive recycle bin?

For personal accounts, files deleted from OneDrive are kept in the OneDrive Recycle Bin for 30 days. For work or school accounts, items in the recycle bin are automatically deleted after 93 days, unless the files are manually deleted.

How to restore all files from the OneDrive recycle bin?

To restore all files from the OneDrive recycle bin, follow these steps: Log in to your OneDrive site >> Navigate to the recycle bin by selecting the recycle bin icon on the left-hand side of the page >> Select the files or folders you want to restore >> Click on the “Restore” button on the top of the page. The restored file will appear in its original location.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

4 thoughts on “OneDrive for Business: Empty Recycle Bin using PowerShell

  • Hi,
    Why I’m getting this error?
    Connect-PnPOnline : The term ‘Connect-PnPOnline’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    Reply
  • Very helpful, thanks!

    Reply
  • Stumbled across your site while searching for exactly this type of solution, really appreciate the information. However, I do seem to be running into an issue. After iterating through the first 2000 or so OneDrive sites, I notice I appear to be getting throttled. Each subsequent Connect-PnPOnline is delayed for 5 minutes before the connection is established and then the cleanup runs quickly and without issues, but upon attempting to connect to the next site, once again, there is a 5 minute delay. Have you encountered a similar issue and can you suggest a workaround? Thank you!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *