Home
Do you clean useless calendars in SharePoint?
  v3.0 Posted at 10/12/2015 10:13 AM by Ulysses Maclaren
Most SharePoint site templates contain a calendar list, this will bring lots of useless calendars.

​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 SettingsRecycle Bin:

EmptyCalendarsInRecyckeBin.png
​Figure: Empty Calendars in Recycle Bin folder


Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments: