Recently (yesterday) I had a need to create 100 document libraries for a demo to a client.  Their initial thought was that they wanted one document library per task group so that the libraries would be in the left navigation.  I wanted to show them what they would actually look like so I created a PowerShell script to create the libraries for me.  The code was rather easy (after some Google Searches) and I cribbed from SharePointRyan’s blog post that creates a New-SPList function.  To that, I added a quick while loop to add 100 libraries.  Note, that I did add one line that makes the libraries visible in the Quick Launch…that was done by using the OnQuickLaunch setting (e.g.)

$list.OnQuickLaunch = "True"

Here is the code (mostly thanks to SharePointRyan.

 

Yeah, nothing special, but in just a few seconds I had 100 Document Libraries Called Application 1 to Application 100.

SNAGHTML477a0545

Then, I wanted to show them what it would look like with 100 Folders instead.  Back to PowerShell for a little folder creation.  This was a bit of fun as I had to track down how to make the folders.  This code was simpler, but I ran afoul of the GetList method wanting the fully qualified path to work.  I got a weird error when I ran it the first time:

 

Exception calling "GetList" with "1" argument(s): "<nativehr>0x80070002</native
hr><nativestack></nativestack>"
At line:1 char:23
+ $list = $spweb.getlist <<<< ("Pharma Docs")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

 

This was because I used GetList with only the name of the list.  Finally I got it to work looking like:

 

Grab the Web, and then grab the list (using the full relative path).  Then use the $list.AddItem command to add the folders.