How can I check if a Document Library is empty or not using powershell.

$web = Get-SPWeb http://skynet 
ForEach($list in $web.Lists)

if($list.BaseType -eq "DocumentLibrary")
    Write-Host $list.Fields
    if($list.Fields.ContainsField("GPMS marking") -eq $true -AND documentlibrary ISNOT empty)
        Write-Host "found" $list.Title
  • does the library contain (nested) folders or just doc files? Commented Jun 9, 2014 at 16:35

2 Answers 2


You can get the count of the items in document library as:

 Count = $List.Folders.Count + $List.Items.Count 

And use the condition accordingly.


I think you need to change you logic, before checking the If statement, you have to count the Number of items(ItemCount) in the Document library. Because their is no OOTB property /Method to check this.

If item Count is not equal to zero then you can do the IF statement for contain fields. else you can do what else you want.

here are 2 MSFT staff Blogs for checking the Item Count into the Library.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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