1
votes

I'm trying to make a script to help automate this process a bit but am fairly new to using PowerShell with SharePoint and don't really know the route to take.

I have a list of 40 items and I need to make a library for each one. Each library then needs to have unique permissions with 3 default groups(Owners, Members, Visitors). The groups should be named the same as the List.Title + Owners/Members/Visitors.

So far I create a site group as follows:

# Owner Group
$web.SiteGroups.Add(“$web Owners”, $web.Site.Owner, $web.Site.Owner, “Use this group to     grant people full control permissions to the $web site”)
$ownerGroup = $web.SiteGroups["$web Owners"]
$ownerGroup.AllowMembersEditMembership = $true
$ownerGroup.Update()

The naming of my groups needs to be the list title and not the web name as I have above.

I create a new library like this:

PS > $spWeb = Get-SPWeb -Identity http://SPServer 
PS > $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 
PS > $spWeb.Lists.Add("My Documents","My Doc Library",$listTemplate)

Clearly this is not automated at all and no faster than just using the GUI to make each new library and adding in the site groups. Can anyone help get me started on a script that would iterate through a list of names create a library and create 3 groups on the site for each new library?

Thanks!!

1
What does the object containing the 40 list items look like? - websch01ar
It's in a SQL database as well as just a list in an excel document. - Braden

1 Answers

1
votes

This should get you on the right track I believe.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$Lists = @("My Documents", "My Docs", "Testing")
$Groups = @("Owners", "Members", "Visitors")
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary

$Web = Get-SPWeb "Your_URL"

$Lists | ForEach-Object {
    $ListName = $_
    $Description = "$_ Description"
    $Web.Lists.Add($ListName, $Description, $listTemplate)
    $Groups | % {
        $GroupName = "$ListName $_"
        $Web.SiteGroups.Add($GroupName, $Web.Site.Owner, $Web.Site.Owner, "Group $GroupName created by automatic process")
        $group = $Web.SiteGroups["$GroupName"]
        if ( !$GroupName -contains "Visitors")
        {
            $group.AllowMembersEditMembership = $true
        } else
        {
            $group.AllowMembersEditMembership = $false
        }
        $group.Update()
    }
}