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

Fine Regards

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

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 ) 
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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