Forum Discussion
Charisma Riley
Jan 06, 2020Copper Contributor
Empty Corporate OneDrive Recycle Bins from PowerShell
I am looking for a simple method (possibly a PowerShell script) that will completely empty OneDrive recycle bins (incl. the secondary recycle bins) within a given URL `[tenant]-my.sharepoint.com/pers...
- Jan 06, 2020Use CSOM API in your code or PnP cmdlets instead
Jan 06, 2020
Use CSOM API in your code or PnP cmdlets instead
- Charisma RileyJan 07, 2020Copper Contributor
jcgonzalezmartin Thank you. What would a script look like that empties both the regular and secondary recycle bin for the OneDrive account in question? Would the URL remain `[tenant]-my.sharepoint.com/personal/[username]`? The script I use for our SPO tenant looks like this (this one empties the regular recycle bin):
Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $Ctx.Credentials = $Credentials #Move All Deleted Items to 2nd Stage Recycle bin $Ctx.Site.RecycleBin.MoveAllToSecondStage() $Ctx.ExecuteQuery() } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red }How can I modify this for a user's OneDrive? Thanks again!