Happy new year! Time to shed bad habits, make resolutions, and perhaps most importantly for SharePoint admins: embark on the great New Year cleanup. While everyone else is busy reorganizing their closets, we get the joy of tidying up SharePoint libraries bursting at the seams. Let’s roll up our digital sleeves and dive into this delightful task with the help of our trusty sidekick: PowerShell.
The SharePoint Tenant Cleanup: Why It Matters
As the year ticks over, your SharePoint tenant is likely groaning under the weight of neglected document libraries, outdated lists, and a staggering amount of files. Among these, libraries with over 5,000 items are particularly problematic. Why 5,000? Because it’s the magic threshold where SharePoint starts giving you that dreaded throttling error and the weird behaviours — the digital equivalent of the twilight zone.
Fear not! A little PowerShell magic can help us identify these bloated libraries and export them to a handy CSV file for further action.
The Game Plan
- Identify all document libraries with more than 5,000 items.
- Export the results to a CSV file for easy review.
- Feel like a SharePoint superhero.
Ready? Here’s the PowerShell Script
First, open your favorite PowerShell environment. Make sure you have the SharePoint Online Management Shell installed. Then, run the following script:
# Connect to your SharePoint Online admin center
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interacti
# Initialize an array to store results
$LargeLibraries = @()
# Get all site collections in the tenant
$sites = Get-PnPTenantSite -IncludeOneDriveSites $false
# Loop through each site collection
foreach ($site in $sites) {
Write-Host "Checking site: $($site.Url)"
# Connect to the site
Connect-PnPOnline -Url $site.Url -UseWebLogin
# Get all document libraries in the site
$libraries = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 }
# Loop through each library
foreach ($library in $libraries) {
# Get the item count
$itemCount = $library.ItemCount
# Check if the item count exceeds 5000
if ($itemCount -gt 5000) {
# Add the library details to the array
$LargeLibraries += [PSCustomObject]@{
SiteUrl = $site.Url
LibraryTitle = $library.Title
ItemCount = $itemCount
}
}
}
}
# Export the results to a CSV file
$LargeLibraries | Export-Csv -Path "LargeLibraries.csv" -NoTypeInformation -Encoding UTF8
Now that you have your list of large libraries, it’s time to take action:
- Archive or delete old files. Check if the content is still relevant. If not, archive or delete it.
- Split large libraries. If a library is too big, consider breaking it into smaller, more manageable libraries.
- Set retention policies. Ensure that you’re not holding onto data longer than necessary.
Just like that, you’ve kicked off the new year with a SharePoint tenant that’s a little lighter and a lot happier. So while your colleagues are agonizing over their personal resolutions, you can sit back with a smug smile, knowing that your SharePoint house is in order.
Happy New Year and happy cleaning!