I have been scraping my head for a while thinking of what is the best practice for deleting a large amount of lists, approximately 8000 lists.

I have developed a PowerShell script that simply loops through a given web application Url for empty lists based on given list BaseTemplate id to delete them.

I've searched the web for some tips, came across bulk operations using ProcessBatchData towards list items, NOT the lists themselves!

What should I consider in my script? Should I take another approach?

All suggestions are welcome and if any further input is needed please let me know!

  • Embedding your script might help a little.. :) – Christoffer Aug 11 '16 at 12:05
up vote 0 down vote accepted

There is generally nothing wrong with this approach and is fairly standard when dealing with operations across the farm in either PowerShell or server object models. Are you encountering any issues or performance problems?

An alternate method might be to leverage search to find all the lists, then iterate through them deleting each one.

  • Correct! It sounds like a less stressing idea to output the empty lists to a CSV file then loop the file and delete the lists accordingly. – Eliya Amanoeel Aug 11 '16 at 12:45

Bulk Operations are against data.

In case of list you can simply use the Delete method associated with the list object. I am not sure how you are find the lists. I would prefer below approach

$webs = (Get-SPSite -limit all | Get-SPWeb -Limit all -ErrorAction SilentlyContinue)  
if($webs.count -ge 1 -OR $webs.count -eq $null)  
{  
    foreach($web in $webs)  
    {  
        #Grab all lists in the current web  
        $lists = $web.Lists     
        foreach($list in $lists)  
        {  
            #check condition and delete
        } 
        $web.Dispose()  
    }  
} 
  • Great Amal! Thanks for the input. My script is more or less the same as yours. :) – Eliya Amanoeel Aug 11 '16 at 12:46

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.