SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am able to search all folders with their name by using


this will display all folders which starts with name a in a Document Library.

I want all folders to be searched only from root level of Document library with name "a" and it should include all its subfolders inside it which can starts with any letter but property StartWith() doesn't exist for $RootFolder.SubFolders

any other way to do it?

share|improve this question

$RootFolder.SubFolders will give you the collection of folders. Loop through the collection and use StartsWith with each folder:

$folders =  $RootFolder.SubFolders;
foreach ($folder in $folders)
    if ($folder.Name.StartsWith("a"))
         // Call $folder.Subfolders again to get folders present in this folder
         // Then use foreach to loop thru each folder and get files inside them


Once inside the folder, call SubFolders again on the folder and then loop through all those folders to get files inside them.

share|improve this answer
what you have given is correct. but my requirement was to download all folders with name" a" at $RootFolder.SubFolders and also it should download all folders inside those folders which can starts with any name. – SharePointHacker Mar 10 '14 at 6:27
You did not mention about downloading in the question, even though I can see the download tag. But it will be better if you update the question – Nadeem Yousuf Mar 10 '14 at 6:31
yes.i will update the question. but any work around for it? – SharePointHacker Mar 10 '14 at 6:33
See my update answer – Nadeem Yousuf Mar 10 '14 at 6:47
Nadeem one more problem.i am ble to get folder level only till root to interate all folder levels – SharePointHacker Mar 10 '14 at 12:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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