Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

Powershell Script to create "custom" Document Library

$
0
0

I have a powershell script which creates a Document Library for every user in AD.

This works, but rather than using the default Document Library I want it use a custom Document Library.  However this isnt working.

My script to create the default Document Library is this...

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$site = new-object Microsoft.SharePoint.SPSite("http://servername/sitename");
$siteweb = $site.OpenWeb();
$webs = $siteweb.Webs;
$strFilter = "(&(objectCategory=User)(name=accountname))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colProplist = "samaccountname"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
    $objItem = $objResult.Properties; $objItem.samaccountname
    $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
    $listId = $siteweb.Lists.Add($objItem.samaccountname, "", $listtemplate);
    $list = $siteweb.Lists.GetList($listId, $true);
    $roleDef = $siteweb.RoleDefinitions.GetByType("Contributor");
        $user = "domain\" + $objItem.samaccountname;
    $rolAssign = new-object Microsoft.SharePoint.SPRoleAssignment($user, "email", "name", "notes");
    $rolAssign.RoleDefinitionBindings.Add($roleDef);
        if(!$list.HasUniqueRoleAssignments)
            {$list.BreakRoleInheritance($true);}
    for ($i = $list.roleAssignments.Count - 1; $i -gt -1; $i--)
        { $list.RoleAssignments.Remove($i) }
    $list.RoleAssignments.Add($rolAssign);
    $list.Update();
}

Now I have a custom Document Library named "TESTLIB" so if I substitute the line:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary

with

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::TESTLIB

Then it errors with this...

How can I script powershell to create a "custom" Document Library?

Thanks






Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>