0

I have a site collection under which i have created a sub-site with unique permissions,

this sub-site has following groups

Community Site Owners  SharePoint Group     Full Control

Project Site Members   SharePoint Group     Contribute

Project Site Owners    SharePoint Group     Full Control

Project Site Visitors  SharePoint Group     Read  

Note: There is no user peresent in any of these groups

I am running a powershell script

$websites = Get-SPWeb "http://XYZ/*"
foreach($web in $websites)
{
    Write-Host  "`r`n`r`n---------------------------------"$web.Title ":" $web.Url "---------------------------------"

    $groups = $web.Groups
    Write-Host $groups.Count
    foreach($grp in $groups)
    {
     $Count++
         Write-Host  "`r`n`r`n---------------------------------`r`n" $Count ":" $grp.Name "`r`n---------------------------------"
       if($grp.Name -ne "NT AUTHORITY\authenticated users"){
             GetUsersRecursive $web $grp
        }
    }
 }

Now When my sub-site doesn't have user in any of groups my $groups.Count is 0 and $web.Title is not printed

OUTPUT When no user in Group

---------------------------------  : http://XYZ/projectsite ---------------------------------
0

but when I add a user the output shows all groups and even prints the Title property of $web

OUTPUT when a single user is added to one of the groups of sub-site

--------------------------------- Project Site : http://XYZ/projectsite ---------------------------------
4


---------------------------------
 1 : Community Site Owners 
---------------------------------


---------------------------------
 2 : Project Site Members 
---------------------------------
User1


---------------------------------
 3 : Project Site Owners 
---------------------------------



---------------------------------
 4 : Project Site Visitors 
---------------------------------

I am trying to understand why this happens, while if i implement same logic in C# i am able to retrieve everything properly. Can someone explain this behaviour of powershell?

0

Is it that your user does not have permission to the site because it's not in any of the groups.

As a test add the user that is running the powershell script as site collection admin, just to see if you can then see the groups ok.

  • No i don't think so because even if this user is not present in any of the groups it would still print the output for other user, I suppose this is not user specific behaviour, I am running code in powershell using site collection admin account. – Akshay Randive May 27 '15 at 9:01
0

Not sure how you are getting subwebs. It should be foreach($web in $websites.Webs). That aside you could try using the AssociatedGroups property. In theory Groups should only return groups that have security roles assigned while AssociatedGroups will return all groups whether they have roles assigned or not.

Edit: When I tested this with two sites a and b. Three unique groups both site not inheriting security. It works fine:

--------------------------------- b : http://test/sites/res/b ---------------------------------
3


---------------------------------
 3 : Empty Group a
---------------------------------


---------------------------------
 4 : Empty Group B
---------------------------------


---------------------------------
 5 : Empty Group C
---------------------------------


--------------------------------- a : http://test/sites/res/a ---------------------------------
3


---------------------------------
 6 : Some Group 2
---------------------------------


---------------------------------
 7 : Some group One
---------------------------------


---------------------------------
 8 : Some Group three
---------------------------------
  • When your URL is "http ://something/* (don't miss asterisk) it will iterate all sites underneath your http: //something I tried with AssociatedGroups but the output is same, no change – Akshay Randive May 27 '15 at 9:16
  • Sorry missed the *. I tried this on a new site collection in 2013 sp1 with a few sub sites and it worked as expected... What version of SP are you using? – Bunzab May 27 '15 at 10:14
  • To be clear I have 3 groups with no members and they all displayed correctly. – Bunzab May 27 '15 at 10:16
  • 1. have you applied "Unique permissions" for subsites? 2.These groups may not be AssociatedOwner/AssociatedMember/AssociatedVisitors, they can be any custom created groups. 3. I am using SP2013 SP1 4.Can you justify me getting $web.Title is not printed?. This is so odd of SharePoint – Akshay Randive May 27 '15 at 11:02
  • 1. Yes 2. They aren't. See my edit. 4. sorry I have no idea. Maybe try using ISE and then debug line by line. – Bunzab May 27 '15 at 11:22

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.