Removing libraries that don’t allow deletion in SharePoint

Despite working with SharePoint for a long time now the fact that there are libraries that can’t be deleted by simply going to the list settings page is one of those things that I haven’t come across too often. If there’s no ‘Delete this library’ link what can be done – well, as is becoming the norm, PowerShell to the rescue!

Scenarios where you may see a library like this would be in a site with the publishing feature enabled. For the case of libraries like the Images library, Documents library or even the Site Collection Documents library it is simply not possible to remove them from the lists settings page or the manage content and structure tool.
Library Options Without Delete

The reason for this is that on creation the library has been set as False for the property AllowDeletion, as you can see in the screenshot below:
The AllowDeletion Property In PowerShell

It is obviously possible to delete the library completely using PowerShell (simply by calling the Delete() method on the list) however both for demonstrations purposes – and also so that you can be absolutely sure that you’re deleting the correct library! – I like the approach of updating the AllowDeletion property to True and then deleting the library through the browser.

This can be done with the simple PowerShell below:

$web = Get-SPWeb http://sp2010/sites/publishing
$list = $web.Lists["Documents"]
$list.AllowDeletion = $True
$list.Update()

And now it’s possible to delete the library through the browser!
Library Options With Delete

Did you spot the bonus feature? By doing the above we also enable the ability to save the library as a template too. I haven’t given this a go (as I wanted to get rid of my library not create more from it!) but I can’t immediately think of a reason why it shouldn’t work.

Note – as I was preparing this post I noticed a similar post from an ex-colleague who’d used the same approach to remove a Drop Off Library created by the content organiser feature in SharePoint 2010. You beat me to the punch Paul!

[By the way, in case you’re thinking that this may never be used, I actually had to use it in anger recently when a migration had gone wrong and migrated/ created an image library on a publishing site that couldn’t be deleted any other way.]

share and enjoy
  • Print
  • Twitter
  • Digg
  • del.icio.us
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

8 comments to Removing libraries that don’t allow deletion in SharePoint

  • […] This post was mentioned on Twitter by Paul Barton, Glyn Clough. Glyn Clough said: New #SP2010 post on removing #SharePoint libraries that don't have the delete option through PowerShell http://bit.ly/i7xEdU […]

  • Mark Ballard

    Bravo!! Thank you very helpful

    Just an fyi – if you are a powershell newb like I am, you’ll need to add this line to the begining of the script so that all the sharepoint commands are recognized.

    Add-PSSnapin Microsoft.Sharepoint.Powershell -erroraction SilentlyContinue

  • Steve V

    Thanks Glyn. It’s these little nuggets of information that help make Sharepoint usable in the real world 🙂

  • Hi Glyn. Do you know the impact of deleting that library? Is peacefull?

    thanks.

  • Kirk

    Unfortunately I can’t delete a document library using this method. Powershell command throws an error: This list cannot be deleted:

    PS C:\Users\sp_farm_prd> $library.Delete()
    Exception calling “Delete” with “0” argument(s): “This list cannot be deleted.”
    At line:1 char:16
    + $library.Delete <<<< ()
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

  • Thank you, Powershell is wonderful! CAML on the other hand…

  • Matt

    Digging up an old post, Sorry.

    I used this today as I had a library that was corrupt or didn’t upgrade correctly from 2007 to 2010. The pages in the library would gobble up all the RAM and CPU on the web server when editing. This would bring the whole web server to a crawling stop until we performed a IIS recycle to recover. The page was just a content editor with nothing special and even closing/deleting the web part didn’t solve the problem.

    I recreated the content in a new library and powershell’ed the Publishing Page library to the new library. I was then able to use your method above to delete the bad library.

    Thank you for your contribution.

    Remove comment markers to execute and make changes.

    CLEAR
    Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue
    $web = get-spweb http://site/subsite/subsite/subsite/
    $correctId = $web.Lists["Site Pages"].ID
    #$web.AllProperties["__PagesListId"] = $correctId.ToString()
    #$web.Update()

    $web = get-spweb http://site/subsite/subsite/subsite/
    $list = $web.Lists["Pages"]
    $list.AllowDeletion = $True
    #$list.Update()

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>