0

I have a script running in Azure Automation that creates group connected SharePoint-sites.

The basic line of code for creating site is this:

New-PnPSite -Type TeamSite -Title $Title -Alias $Alias -Lcid 1053

This creates a standard Team site with no additional owners or members.

In a following step we add members to the group utilizing exchange module like this example:

Add-UnifiedGroupLinks -Identity $unifiedGroup.Id -LinkType Member -Links $member.Email 

The reason why we do this is because in between these two steps we disable the welcome mail and it is of high importance to our organization that no standard welcome mail goes out. Therefore members has to be added post-creation.

While the above lines of code work just fine the problem occurs when permissions seem to take forever to reflect from group to SharePoint. Same thing goes if we add membership with graph. I have also tried utilizing SP.Directory.DirectorySession rest API endpoint through PowerShell web request but I'm stuck with a 403 on that one...

In short what we want. Create a group with no welcome mail going out. Add group permissions immediately reflected to SharePoint. Is there a way to make this work?

0

I think this could be due to the fact that Team site is being created with a different account while script to add members is running in a different session. have you tried using Set-PnPUnifiedGroup

Set-PnPUnifiedGroup -Identity $groupId -Members foo@contoso.com 

Members values should be a string array in case of multiple users

3
  • This apporach seem to work better than using the exhange module for assigning group membership but not totally so when adding group ownership. When adding a group owner, the user will get access to sharepoint as a site collection admin, just as supposed to, But it takes time, probably an hour or so in my tenant, before the group membership pane updates and says that this user is now in fact an owner. Any ideas?
    – Fred
    Aug 31 '20 at 14:48
  • When you are adding any person as Owner, first add him as member and then make him Owner. this works usually more faster. Aug 31 '20 at 16:31
  • It actually seem to work when using New-PnPUnifiedGroup and adding owners and memebrs directly in this command, This however, only works executed from my machine but fails to add owners and members when using azure automation. App used for authentication and PnP-version is the same one. Any ideas why it fails to work properly in azure automations? No error message and site is created but owners is not taken care of. Example code used: New-PnPUnifiedGroup -DisplayName $DisplayName -Description $description -MailNickname $Alias -Owners "owner@contoso.com" -Members "member1@contoso.com"
    – Fred
    Sep 2 '20 at 11:07

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.