How to add Security groups to Sharepoint groups?

Romian Tairovski 21 Reputation points
2022-04-06T11:49:33.45+00:00

Hello,

I'm creating a Microsoft Team programmatically, via Graph Calls. After creating a Team, a sharepoint is automatically created and I'm creating a folder structure in the Sharepoint.

I want to add security groups to the sharepoint groups

In the screenshot below you see the Sharepoint Groups
190539-image.png

Here you can see I can add a security group to the Sharepoint group by useing the user interface.
190518-image.png

This all works, but I want to do it programmatically. Are there Graph calls I can use? Or do I need to use Powershell or C#?

Thanks for reading and I hope someone can help.

Romian Tairovski

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2022-04-07T02:09:51.297+00:00

    Hi @Romian Tairovski ,
    I will recommend you to use PowerShell, in which case your best bet is the Add-SPOUser cmdlet, which "Adds an existing Office 365 user or an Office 365 security group to a SharePoint group."
    Here is the example

    $SecGroupName = "TestSecurityGroup"        # The security group DisplayName  
    $SPOGroupName = "TestSharePointGroup"      # The SharePoint Online group  
      
    # Get the SharePoint site  
    $SPOSite = Get-SPOSite "https://contoso.sharepoint.com"  
      
    # Add the security group as a member of the SharePoint Online group  
    Add-SPOUser -Site $SPOSite -LoginName $SecGroupName -Group $SPOGroupName  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



0 additional answers

Sort by: Most helpful