2

I am working on office 365 SharePoint site.

I want to fetch all lists/libraries/items where permissions are given to Everyone group across SharePoint site using CSOM.

    Web web = context.Web;
var Lists = context.Web.Lists;
context.Load(Lists);
context.ExecuteQuery();
foreach (var List in Lists)
{
    context.Load(List.RoleAssignments);
    context.ExecuteQuery();
    foreach (var RoleAssignment in List.RoleAssignments)
    {
        context.Load(RoleAssignment.Member);
        context.ExecuteQuery();
        var EveryoneexceptexternalUsers = " c:0-.f|rolemanager|spo-grid-all-users/526bf739-e2f7-4c87-a8ce-0737198cc796";
        PrincipalType SharePointGroup = default(PrincipalType);
        if (RoleAssignment.Member.PrincipalType == SharePointGroup && RoleAssignment.Member.LoginName == EveryoneexceptexternalUsers) {
            Console.WriteLine(List.Title, "has Everyone Group");

        }
        else
        {
            Console.WriteLine("Everyone group is not present in the List");
        }
        Console.ReadLine();
    }
}
  • I didn't run the PowerShell script. Instead of PowerShell converted that into csom. I have posted my code here. I have added everyone group in a list. when I run the code it is not fetching the list name instead of that it is executing else condition. – Maha Jul 26 at 8:07
0

To achieve your requirement, there is a PowerShell script for your reference.

    #Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = "https://tenantname.sharepoint.com/sites/sitename"
$UserName="username"
$Password ="password"

#Setup Credentials to connect

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))


    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 

    $Context.Credentials = $credentials


    #sharepoint online powershell get all lists

    $Lists = $Context.web.Lists

    $Context.Load($Lists)

    $Context.ExecuteQuery()



    #Iterate through each list in a site   

    ForEach($List in $Lists)
    {

        $Context.Load($List.RoleAssignments)
        $Context.ExecuteQuery()
        Foreach($RoleAssignment in $List.RoleAssignments)
        { 
               $Context.Load($RoleAssignment.Member)

               $Context.executeQuery()

               If($RoleAssignment.Member.PrincipalType -eq "SharePointGroup" -And $RoleAssignment.Member.LoginName -eq "Everyone"){

                    Write-host $List.Title "has Everyone Group"

                } 

        }




    }   

More reference:

SharePoint Online: Site Collection Permissions Report using PowerShell.

  • But still not able to fetch. – Maha Jul 24 at 11:31
  • did you encounter the error when running the powershell script? – Amy_MSFT Jul 25 at 1:49
  • I didn't run the PowerShell script. Instead of PowerShell converted that into csom. I have posted my code here. I have added everyone group in a list. when I run the code it is not fetching the list name instead of that it is executing else condition. – Maha Jul 25 at 6:10
0
 Web web = context.Web;
                var Lists = context.Web.Lists;
                context.Load(Lists);
                context.ExecuteQuery();
                foreach (var List in Lists)
                {
                    context.Load(List.RoleAssignments);
                    context.ExecuteQuery();
                    Console.WriteLine(List.Title);
                    if (List.Title.StartsWith("Employee"))
                    {
                        foreach (var RoleAssignment in List.RoleAssignments)
                        {
                            context.Load(RoleAssignment.Member, r => r.LoginName, r => r.PrincipalType);
                            context.ExecuteQuery();
                            var EveryoneexceptexternalUsers = "c:0-.f|rolemanager|spo-grid-all-users/526bf739-e2f7-4c87-a8ce-0737198cc796";
                            //PrincipalType SharePointGroup = default(PrincipalType);
                            if (RoleAssignment.Member.LoginName == EveryoneexceptexternalUsers)//RoleAssignment.Member.PrincipalType == SharePointGroup && 
                            {
                                Console.WriteLine(List.Title, "has Everyone Group");
                            }
                            else
                            {
                                Console.WriteLine("Everyone group is not present in the List");
                            }
                        }
                    }
                    Console.ReadLine();
                }
  • I have done small changes now it is working – Maha Jul 26 at 10:18
  • Note that neither this nor the other answers here address your requirement to check permissions on list items that may have unique permissions – sasfrog Jul 26 at 21:55

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.