To empty the recycle bin in SharePoint using PowerShell, you can use the EmptyRecycleBin
method of the RecycleBin
class. Here's a simple script to accomplish this:
# Load SharePoint PowerShell snap-in
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
# Specify the URL of the site
$siteUrl = "https://your-sharepoint-site-url"
# Connect to the SharePoint site
$site = Get-SPSite $siteUrl
# Get the recycle bin of the site
$recycleBin = $site.RecycleBin
# Empty the recycle bin
$recycleBin | ForEach-Object { $recycleBin.Delete($_.ID) }
# Dispose of the SharePoint site object
$site.Dispose()
Write-Host "Recycle bin emptied successfully."
replace "https://your-sharepoint-site-url"
with the URL of your SharePoint site.
This script connects to your SharePoint site, retrieves the recycle bin, and then iterates through each item in the recycle bin, deleting them one by one. Finally, it displays a message indicating that the recycle bin has been emptied successfully. Make sure to run this script with appropriate permissions, as it requires sufficient rights to delete items from the recycle bin.