GitHub Icon Image
GitHub

Empty SharePoint Online Site Recycle Bin

Summary

This sample script shows how to empty SharePoint online site first stage and second stage recycle bin.

Scenario inspired from this blog post: SharePoint Online: Empty Recycle Bin using PnP PowerShell

Outupt Screenshot

  • PnP PowerShell
  • CLI for Microsoft 365

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Move all items from the first stage recycle bin to the second stage recycle bin
Move-PnPRecycleBinItem

# Empty second stage recycle bin in SharePoint site
Clear-PnPRecycleBinItem -SecondStageOnly

# Empty both first stage and second stage recycle bin in SharePoint site
Clear-PnPRecycleBinItem -All

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell


# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
   m365 login
}

# Empty first stage recycle bin in SharePoint site permanently
m365 spo site recyclebinitem clear --siteUrl $siteUrl

# Empty second stage recycle bin in SharePoint site
m365 spo site recyclebinitem clear --siteUrl $siteUrl --secondary

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Contributors

Author(s)
Ganesh Sanap

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI