SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to delete list from a site collection using power shell commands. Can anyone help me with the code.

[Actual requirement : Delete all list which starts with "xyz"]

share|improve this question
up vote 6 down vote accepted

Here it is:

$startsWith = "ABC"
$site = Get-SPSite http://mycoolsite
$webs = $site.AllWebs

foreach ($web in $webs) {
    $lists = $web.Lists
    for ($index = 0; $index -lt $lists.Count; $index++) {
        if ($lists[$index].Title.StartsWith($startsWith)) {

share|improve this answer
can you also provide the generalized code to delete list with list name specified. – Monica Jagani Sep 6 '11 at 12:18
@MonicaJagani - for this generalized code: Do you know web location or do you need to search all webs in site collection to find it? You can easily modify provided code to do second: just use 'if($lists[$index].Title -eq $startsWith)'. This will delete list with name defined in $StartsWith – Vedran Rasol Sep 6 '11 at 12:30
It works better if you iterate backwards while deleting; the listed code didn't quite work for me - for ($index = $lists.Count - 1; $index -ge 0; $index--) { – lgaud Mar 21 '13 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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