I'm trying to work out how I can locate empty folders in Sharepoint 2007 using Powershell. Folder.itemcount doesn't appear to work in 2007.

2 Answers 2


There is an artile on TechNet with explained ways to find the missing folders.

There is another way, as described on this blog from http://geektechlive.com/ titled Find all empty folders in sharepoint shared document repositories, though it is not done via PowerShell, but via simple SQL query on the SharePoint WSS_Content Database. Cite:

I query the Docs View and only get Type of 1 which seems to be folders. I also limit the query to DirName of Shared Documents and make sure that nested folders are recursively checked.

SELECT DirName as [Path], LeafName as [FolderName],ItemChildCount as [Items In Folder]
Where [TYPE] = ’1′
and DirName like ‘%Shared Documents%’
And DirName not like ‘%Shared Documents/Forms%’
and ItemChildCount = 0
and FolderChildCount = 0
and DoclibRowId is not null
Group by DirName, LeafName,ItemChildCount
order by Dirname, FolderName

The author also mentions:

This is not supported by Microsoft so if you kill your server its not anyone’s fault but your own. Be forewarned!


SP2007 isn't configured to work with Powershell. Unfortunately I'm not aware of any stsadm command which will do this for you. I'd recommend using the SharePoint API in Visual Studio to find this information.

using(SPSite site = new SPSite("http://yoursiteurl/")
    using(SPWeb rootWeb = site.Rootweb)
        foreach(SPFolder folder in rootweb)
            if(folder.Items.Count == 0)
                Console.WriteLine("The folder " + folder.Name + " is currently empty.";

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.