Do you clean useless calendars in SharePoint?

Updated by Brady Stroud [SSW] 1 year ago. See history

123
No component provided for introEmbed

Use the below PowerShell script to clean them:

$site = Get-SPSite("http://<site collection URL>/"); # Specify url here
foreach ($web in $site.AllWebs) {
$lists = $web.Lists
for ($i=($lists.Count-1);$i -gt 0; $i--) {
$list = $lists[$i]
#Write-host $i $list.Title $list.BaseTemplate.ToString()
if ($list.BaseTemplate.ToString().ToLower().contains('events')) {
if ($list.Items.Count -eq 0)
{
Write-Host $list.Items.Count "items in the list" $list.Title '('$list.BaseTemplate') at '$web.Url "- cleaning it!"
$list.Recycle()
#$list.Delete()
}
}
}
}

This script will put the calendars which do not have any events into Site Settings | Recycle Bin:

Image

Figure: Empty Calendars in Recycle Bin folder

Acknowledgements

William Yin
Brendan Richards
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star