Programmatically checking who is a member of a SP Group

It is pretty straight forward to see if a user is in a SP Permissions Group. Take a look at the example JSOM below:

So now you have the JSOM to check if the logged in user is a member of a specific SP Group, the problem is that by default only current members of a given group can view the group membership. Now if you tried the method that I suggested with a user who was not in the group (with these default settings), you would get an access denied message (403 error).

So in SPO, you can use one of the few commands to create a new SP Group, with one line of code:

Once the group has been created, if you look at the settings, you will see that by default the only people who can view membership of this group are those who are a current member:

060514_1101_Programmati1

This needs to be amended either via the UI or using CSOM so that ‘Everyone’ can view the membership of the SP Group, after the group has been created. Luckily Sharepoint’s SPGroup has a ‘OnlyAllowMembersViewMembership’ property which can be set to false to achieve this via script.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spgroup.onlyallowmembersviewmembership(v=office.15).aspx

If you need to do this in PowerShell for SPO, take a look at the following example (you will need an open connection before running the PowerShell script):

Programmatically checking who is a member of a SP Group

Leave a Reply

%d bloggers like this: