0

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

Fine Regards

1
  • Yes, it's possible. Where exactly you stuck at?
    – user656
    Commented Jun 16, 2012 at 4:57

1 Answer 1

3

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 ) 
2
  • I tried it but it doesn't work as expected? Can you test your codde as well?
    – Geek
    Commented Jun 17, 2012 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
    Commented Jun 17, 2012 at 23:19

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.