SharePoint Online CSOM Associated Site Groups AssociatedMemberGroup AssociatedOwnerGroup AssociatedVisitorGroup

StackOverflow https://stackoverflow.com/questions/23432665

  •  14-07-2023
  •  | 
  •  

سؤال

Using the SharePoint Online CSOM, I have created a site and been able to set a number of things on the site. When a site is created using CSOM, the default groups are not created. I have created the groups okay however due to creating the groups outside the site creation process, I now need to assign them as the default groups on the site.

I've got the following code which doesn't come back with any errors in PowerShell but it doesn't set the groups either. Has anyone managed to achieve this?

$MemberGroupId = 101
$OwnerGroupId = 102
$VisitorGroupId = 103

$Web = $ClientContext.Web
$Groups = $Web.SiteGroups

$ClientContext.Load($Groups)
$ClientContext.ExecuteQuery()

$Web.AssociatedMemberGroup = $Groups.GetById($MemberGroupId)
$Web.AssociatedOwnerGroup = $Groups.GetById($OwnerGroupId)
$Web.AssociatedVisitorGroup = $Groups.GetById($VisitorGroupId)
$Web.Update()

I read in a couple of places that people had, had issues with these AssociatedMemberGroup, AssociatedOwnerGroup and AssociatedVisitorGroup properties so had set them instead by using $Web.AllProperties but I'm not sure how to do this and it certainly seems like a more complicated way.

هل كانت مفيدة؟

المحلول

Not sure if you found a solution for this. If not, try the following:

$groups = $web.SiteGroups
$clientContext.Load($groups)
$clientContext.ExecuteQuery()

$group = $groups.GetByName("Your Visitors Group Name")
$clientContext.Load($group)

$web.AssociatedVisitorGroup = $group
$web.Update()

$clientContext.ExecuteQuery()

Let me know how that works.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top