2

I'm trying to create custom permissions in my Sharepoint site via Powershell using the following script:

$spSite = Get-SPSite $url
$spWeb = $spSite | Get-SPWeb

foreach($option in $configuration.Config.permissions.permission)
{
    if($spWeb.RoleDefinitions[$option.name] -eq $null)
    {
        $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition
        $spRoleDefinition.Name = $option.name
        $spRoleDefinition.Description = $option.description

        $spRoleDefinition.BasePermissions = $option.bases
        $spWeb.RoleDefinitions.Add($spRoleDefinition)
    }
}
$spWeb.Dispose()
$spSite.Dispose()

And I keep receiving the following error:

Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."
At C:\xxxx\xxxxxx\xxxxx:70 char:4
+             $spWeb.RoleDefinitions.Add($spRoleDefinition)
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException

Thanks for the help.

2 Answers 2

2

I found the issue:

Instead of using $spWeb = $spSite | Get-SPWeb I used $spWeb = $spSite.RootWeb and it worked fine.

0

Try to run SharePoint Managment shell as a Administrator

1
  • Still not working Commented Oct 29, 2015 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.