Thursday, July 19, 2012

Deleting Inaccessible SharePoint 2010 Lists or Libraries using PowerShell

Some times it happens so that there's a custom list out there in your SharePoint 2007 environment, but for some reason you don't have the definition of the list with which the list / library was created. This will create a situation wherein you won't be able to access these lists after you migrate them to SharePoint 2010, because their definitions aren't available in the SharePoint 2010 environment. In situations like this, you will not be able to access the list and would probably want to get rid of them from the system. If that sounds something that you've been into, then read on...

Recently in a SharePoint 2007 to 2010 migration, I had a scenario just like this. A custom library definition was built and deployed as a feature  inside the SharePoint 2007 environment. This definition was used to create a handful of libraries. This source code of the list definition was lost over time, and the business reason behind the custom definition itself ceased to exist. However, the content within these libraries were still required to be preserved. The SharePoint 2007 environment had the library definition in there, so everything was working just fine. Whereas the definition is no longer available in SharePoint 2010 environment due the fact that the source code of the library definition wasn't available.

In a situation like this, if you try to delete a list using by using the following script, you'd get a nice exception that says that the feature is not installed on the farm due to which the operation couldn't be completed. To get around this issue, get access to the list instance by its ID instead of its Title, then you'll be able to delete the list without any hassle.

 $Web = Get-SPWeb "URL of the site that contains the list to be deleted"  
 $List = $Web.Lists["Title of the List"]  
 $List.Delete()  

Note that you will still have to find a way to get the documents from your 2007 environment along with its metadata into the new document libraries in the 2010 environment. But that is not within the scope of this post.

The following PowerShell command(s) will help you get an instance of a list using its ID and then delete it. USE IT AT YOUR OWN RISK.

 $Web = Get-SPWeb "URL of the site that contains the list to be deleted"  
 $List = $Web.Lists | Where{$_.ID -eq "GUID of the List"}  
 $List.Delete()  

No comments:

Post a Comment