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?

5
  • 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, 2016 at 10:34
  • Please check if it works for you..social.technet.microsoft.com/Forums/office/en-US/…
    – Hardik
    May 20, 2016 at 10:49
  • @Hardik, no I am referring to groups themselves and not users. May 20, 2016 at 11:18
  • Site Collection Groups or only subsite groups?
    – Hardik
    May 20, 2016 at 11:29
  • It is mentioned in my post above. I set it to bold. It is subsite. May 20, 2016 at 11:42

1 Answer 1

-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.

6
  • sorry, but it is not helpful. May 20, 2016 at 12:43
  • Can you prove the code for what you are passing in $web?
    – Hardik
    May 20, 2016 at 12:44
  • It is exactly what you added: $web = Get-SPWeb http://intfin/sites/regions/mytest May 20, 2016 at 12:47
  • Have you checked here?...social.technet.microsoft.com/Forums/sharepoint/en-US/…
    – Hardik
    May 20, 2016 at 12:54
  • Please check updated answer. It will work for you.
    – Hardik
    May 20, 2016 at 12:58

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.