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

Is it possible to iterate through all the lists in a site collections and create a folder name "Test" using PowerShell?

Fine Regards

share|improve this question
Yes, it's possible. Where exactly you stuck at? – avishnyakov Jun 16 '12 at 4:57
up vote 3 down vote accepted

Should be something like:

# get the site collection
$s = get-spsite http://siteurl 

# loop through all site in the site collection, 
# then through all lists / libraries in that site (filtering out everything but actual doc libs 
# (The catalog filter excludes all sharepoint libs like the masterpage catalog etc.
// for each list, add a folder called test to the rootfolder
$s.AllWebs | Foreach-Object { 
  $_.Lists | Where { ($_.BaseType -eq "DocumentLibrary") -and ($_.BaseTemplate -notmatch "Catalog") } | Foreach-Object {

# P.S.  
# not sure if  you need to call the list's update method after adding the folder
# to show folder info, change $_.RootFolder.SubFolders.Add("Test") into
#Write-Host ($_.Title + " - " + $_.BaseType + " - " + $_.BaseTemplate ) 
share|improve this answer
I tried it but it doesn't work as expected? Can you test your codde as well? – Geek Jun 17 '12 at 18:01
Note the "something like" in the answer ;-)? The purpose of this Q&A site is to educate/ learn and find out things on your own (with the provided help of course :-D). You won't learn anything from a completely written script. For now I'll let you of the hook, check the modified answer – Colin Jun 17 '12 at 23:19
way to go Colin. Thanks :D – Geek Jun 18 '12 at 9:45

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.