2

I have different SharePoint groups for sub-site which has unique permissions, I am writing a powershell script and I have come across a point where i need to get the permission level of a XYZ sharepoint group. I tried but i am not able to find a way to retrieve the permission level of given SharePoint group.

I am trying this

    foreach($grp in $groups)
    {
        #get permission level assigned to $grp
    }

1 Answer 1

3

So in the SharePoint Object Model the permissions are not members within the group. they are RoleAssignments tied to the SPList object. This is because a group can have Read access to one list and Edit to another. So you will need to look at every list and search for your group and then display its role assignment.

Try something like this and see if it works for you:

$web = get-spweb http://yourweb    
$list = $web.lists["yourlist"]    
$roleAssignments = $list.RoleAssignments
foreach ($oRoleAssignment in $roleAssignments)
{
    foreach ($member in $oRoleAssignment.Member)
    {
        if ($member.name -eq "XYZ")
        {
            foreach ( $binding in $oRoleAssignment.RoleDefinitionBindings )
            {
                write-host $binding.Name
            }
        }
    }
}

if you want to get deeper in the weeds about the SPRoledefinitionbindingcollection class check this MSDN article out: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.sproledefinitionbindingcollection.aspx

also if you want to start adding and removing permission it will be done similar to this:

$oRoleAssignment.RoleDefinitionBindings.Remove(($web.RoleDefinitions | Where-Object { $_.Name -eq "NAME_OF_THE_PERMISSION" }))
$oRoleAssignment.Update()

I hope this helps answer your question!

3
  • can i get the allthe groups from a site and get all their site permissions
    – samolpp2
    Commented Jun 16, 2017 at 11:36
  • 1
    Sure but you have to be aware that if permissions are broken you still need to look at the lists to get the full picture.
    – EFighter
    Commented Jun 19, 2017 at 17:35
  • ok, am having some 15+ doc libs+ splists , most of them are having broken permissions!
    – samolpp2
    Commented Jun 19, 2017 at 17:36

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.