0

In my project I am creating new subsite and adding documents to it. I need to assign permissions to the documents. As the subsite is newly created there is no user or groups are added to it. I need to get all users and groups from Sharepoint online and add them to SiteGroups and SiteUsers. How can I get all users/groups from the sharepoint online?

Please note: I am not searching for SiteGroups and SiteUsers.

  Web f_web                               = null;
 WebCreationInformation f_webCrInfo      = null;

 f_webCrInfo                     = new WebCreationInformation();
 f_webCrInfo.Description         = "My new substie";
 f_webCrInfo.Title               = "Newsubsite";
 f_webCrInfo.WebTemplate         = "STS";
 f_webCrInfo.Url                 = "subsite";
 f_webCrInfo.UseSamePermissionsAsParentSite = true;
 f_web                           = p_Context.Web.Webs.Add(f_webCrInfo);

 p_Context.Load(f_web, 
                        website => website.Fields,
                        website => website.ServerRelativeUrl,
                        website => website.Url, website => website.Id,
                        website => website.Language,
                        website => website.RegionalSettings,
                        website => website.RoleAssignments,
                        website => website.RoleDefinitions);

 p_Context.ExecuteQuery();
  • a bit unclear, do you want to ensure that everybody in the tenant has access to the sharepoint site ? – Gautam Sheth Mar 15 '18 at 8:38
  • Not everybody but some of them I need to be added to subsite. My app will provide option to choose user/group and end user will select them. So end user should have all the users list – Mayuresh Mar 15 '18 at 8:43
  • You should use AD groups. Adding users individually is going to be a maintenance nightmare. – Derek Gusoff Mar 15 '18 at 13:08
0

By default, SharePoint online users are stored in Azure AD. Do you want to add all AD users in SharePoint site? Or you only want to add all users and groups from parent site in this subsite?

If the latter, links for your references:

how to get users in all groups via PowerShell: http://www.sharepointdiary.com/2017/06/sharepoint-online-site-users-and-groups-report-powershell.html

how to add a list of users and groups in online site: http://3sharp.com/blog/use-powershell-to-automate-groups-and-users-provisioning-in-sharepoint-online/

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.