Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 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 {
    $_.RootFolder.SubFolders.Add("Test")
    $_.Update()
  }
}

# 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
1  
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

 
discard

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.