1

I am able to fetch all the site groups however all this groups are not showing in site. It is showing extra groups when i run the csom power shell and how do i filter only the groups which are showing on site UI.

here is my Sample code

Add-Type -Path "C:\\Microsoft.SharePoint.Client.dll"   
Add-Type -Path "C:\\Microsoft.SharePoint.Client.Runtime.dll"     

#SPO Client Object Model Context 
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 
$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)   
$spoCtx.Credentials = $spoCredentials       

$web = $spoCtx.Web
$spGroups =$web.SiteGroups
$spoCtx.Load($spGroups)
$spoCtx.ExecuteQuery() 

foreach($group in $spGroups)
{
    Write-Host " Group Name = $($group.Title)"
    Write-Host " Group is hidden = $($group.IsHiddenInUI)"
    Write-Host " Group User Count = $($group.Users.Count)"
}

I have 2 question

  1. How do i filter groups which can show only the groups which are showing in Site
  2. $group.IsHiddenInUI, $group.Users.Count is giving not intialized exception exception
  • Are you running these commands on server itself or from a remote machine? – Arsalan Adam Khatri Mar 7 '17 at 7:47
  • Hi, I am running this script from remote machine – Suresh Bolineni Mar 7 '17 at 8:41
2

Change the following in your code to avoid not initialized exceptions:

$web = $spoCtx.Web
$spGroups =$web.SiteGroups
$spoCtx.Load($spGroups)
$spoCtx.ExecuteQuery() 

foreach($group in $spGroups)
{
    $spoCtx.Load($group)
    $users = $group.Users
    $spoCtx.Load($users)
    $spoCtx.ExecuteQuery()


    Write-Host " Group Name = $($group.Title)"
    Write-Host " Group is hidden = $($group.IsHiddenInUI)"
    Write-Host " Group User Count = $($users.Count)"
}

In short since you are using CSOM, you need to load each collection to get it's properties to work otherwise it will throw NOT INITIALIZED EXCEPTION.

  • hi thanks for your answer. I am able to get User count but not able to retrieve the $group.IsHiddenInUI giving the NOT INITIALIZED EXCEPTION – Suresh Bolineni Mar 7 '17 at 8:58
  • Can you please tell me how do retrieve Permission levels tagged for the Groups like "Full Control", "Contribute" – Suresh Bolineni Mar 7 '17 at 9:03
  • Permissions are not tied to groups, they are based on list or library. For example, a group can have View-only access to one list while Full control on another list. – Arsalan Adam Khatri Mar 7 '17 at 9:43
  • However Google for RoleAssignments and RoleDefinitions to get the permissions – Arsalan Adam Khatri Mar 7 '17 at 9:43
  • 1
    Thank you..! I have got through RoleAssignments and RoleDefinitions – Suresh Bolineni Mar 8 '17 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.