1

I'm looking to create multiple document libraries on a list of sites.

I've got most the pieces; I'm just having trouble combining them correctly. Here's the code for making the libraries. If I have 50+ sites(same collection) to make these same libraries on, how should I do that?

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
    $siteColl = Get-SPWeb -Identity http://sitename/
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 

$siteColl.Lists.Add("Library1","",$listTemplate) 
$siteColl.Lists.Add("Library2","",$listTemplate) 
$siteColl.Lists.Add("Library3","",$listTemplate) 

1 Answer 1

1

You can create multiple list using the the following code by reading setting from xml file. You can specified the template as required

$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path

[xml]$config = Get-Content $directorypath"\Libraries.xml"

foreach($library in $config.libraries.library){
    $web = Get-SPWeb $library.web
    $template = [Microsoft.SharePoint.SPListTemplateType]::($library.template)
    $web.Lists.Add($library.url,$library.description, $template);
    $web.Update();

}

Create an xml file called Libraries.xml and copied the following code:

<?xml version="1.0" encoding="utf-8"?>
    <libraries>
      <library>
        <template>DocumentLibrary</template>
        <url>Control</url>
        <title>Document Library1</title>
        <description>This is a Control library</description>
        <web>www.contoso.com</web>
      </library>

      <library>
        <template>DocumentLibrary2</template>
        <url>Control</url>
        <title>DocumentLibrary2</title>
        <description>This is a Control library</description>
        <web>www.contoso.com</web>
      </library>
    </libraries>

For more info, you can have a look into the following post: http://selingernetwork.com/blog/?p=53

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.