0

I am trying to get the sharepoint groups for a particular subsite, but I am getting more groups then what I see via UI. I created a test subsite and I still see more groups. For example: Via UI I see these groups "Test Owners", "Test Visitors", "Test Members", but using powershell I see these extra groups: "Finance Owners", Designers, Act Content Admins, General Workspace Owners, etc.

This is the powershell script I am using. It is really simple.

function GetWebGroups($web){

    if($web.HasUniqueRoleAssignments -eq $True)
    {
        # I have tried using SPGroup
        $groups = $web.Groups
        foreach($group in $groups)
        {
            Write-Host $group.Name -f Yellow
        }

        # And I have tried using Roleassignments
        foreach($webRoleAssignment in $web.RoleAssignments) 
        {
                Write-Host $webRoleAssignment.Member.Name
        }   
    }

}

I have broken the inheritance, but I still get extra groups which I don't see them via user interface.

What could be the reason?

  • By the group names you mentioned in your question, I think that you are trying to get users of your subsite. Please tell me if i am worng. – Hardik May 20 '16 at 10:34
  • Please check if it works for you..social.technet.microsoft.com/Forums/office/en-US/… – Hardik May 20 '16 at 10:49
  • @Hardik, no I am referring to groups themselves and not users. – Burre Ifort May 20 '16 at 11:18
  • Site Collection Groups or only subsite groups? – Hardik May 20 '16 at 11:29
  • It is mentioned in my post above. I set it to bold. It is subsite. – Burre Ifort May 20 '16 at 11:42
-1

I don't know what you are passing in $web. But If you groups from specific subsite than you need to give specific subsite URL in your $web to get all groups for given subsite URL.

UPDATED CODE

    //Pass Subsite URL to get only subsite groups    
    $web = Get-SPWeb http://server/sites/yourSubSite

    function GetWebGroups($web){

        if($web.HasUniqueRoleAssignments -eq $True)
        {
            # I have tried using SPGroup
            $groups = $web.SiteGroups
            foreach($group in $groups)
            {
                Write-Host $group.Name -f Yellow
            }

            # And I have tried using Roleassignments
            foreach($webRoleAssignment in $web.RoleAssignments) 
            {
                    Write-Host $webRoleAssignment.Member.Name
            }   
        }

    }

I hope it will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.