5

How can I perform a check if a document library already exists using Powershell in SharePoint 2010?

7

Something like this:

$w = get-spweb "<webURL>"
$list = $w.Lists.TryGetList("<Title of the list>")
if($list -ne $null)
{
    # The list already exists
}

Replace <webURL> and <Title of the list> with your actual values

  • And is there also a way to check that it is a document library type list and not just a normal list? – motionpotion Nov 5 '14 at 11:42
  • 2
    On the list you can call $list.BaseType. It will return DocumentLibrary for libraries and GenericList for lists – Robert Lindgren Nov 5 '14 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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