How to get Empty Folder from Document Library in SharePoint 2013

This post will show you how to get Empty Folder from Document Library in SharePoint 2013.

 

Question: Customer has a big library along with some empty folders in it. Since the folders are located in the different place, he wants to query on library and get all empty folders.

 

Solution: Get the Empty Folder from Document Library with SharePoint PowerShell.

 

Please open up SharePoint PowerShell and run the following script:

$spsite = Get-SPWeb http://cpshelley/sites/Delta
$splist = $spsite.Lists["Custom1"]
$spquery = New-Object Microsoft.SharePoint.SPQuery
$spquery.Query = "<Where> <BeginsWith> <FieldRef  Name='ContentTypeId' /> <Value Type='ContentTypeId'>0x0120</Value> </BeginsWith> </Where>"
$spquery.ViewAttributes = "Scope='RecursiveAll'"
$splistitemCollection = $splist.GetItems($spquery); foreach ($item in $splistitemCollection) { if ($item.Folder.Files.Count  -eq 0) { Write-Host Empty folder : $item.Url }}

 

Hopefully it is useful for you!