0

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
    }
}
}
1
  • does the library contain (nested) folders or just doc files? Commented Jun 9, 2014 at 16:35

2 Answers 2

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.

0

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.

http://blogs.msdn.com/b/russmax/archive/2012/01/20/sharepoint-powershell-script-series-part-4-gathering-item-count-for-all-document-libraries-in-a-site-collection.aspx

http://geekswithblogs.net/bjackett/archive/2013/06/05/powershell-script-to-determine-number-of-files-in-sharepoint-2010.aspx

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.