I'm fairly new to SharePoint scripting and after much searching I'm reaching out to see if someone can help me with the commands needed to complete this task.

I'm have a SharePoint Online site that contains a document library with broken inheritance. The document library has had some custom SP groups added to it. What I'm trying to do now is figure out how to add an AD group (synced to Azure) to one of the custom SP groups on the document library.

I've made it as far as being able to add the AD group to the document library as its own permission but I cannot figure out how to add the AD group INTO the SP group rather than directly to the document library.

I'm using this code to connect to SP Online and set the AD group as a permission the the document library.

Connect-PnPOnline -Url 'https://<domain>.sharepoint.com/sites/<site>' -Interactive
Set-PnPListPermission -User 'c:0t.c|tenant|<azure_ad_group_id>' -Identity '/<library_name>' -AddRole 'Contribute'

The document library already has SP groups 'Custom Group 1', 'Custom Group 2'. How do I add the AD group to those SP groups?

If this is possible with the normal SharePoint Online PowerShell module I'd prefer to use that, but I'm ok with PnP if that's the only option

1 Answer 1


Adding AD security group to a SharePoint group via Pnp PowerShell

To add an AD security group to a SharePoint Group, you can use Add-PnPUserToGroup commandlet. Even though it says "User", it actually works for AD Groups as well.

Add-PnPUserToGroup -Identity "ClassicTeam Owners"  -LoginName  'c:0t.c|tenant|4902e6a8-4c05-4e17-9b49-459226f6886d' 

And the result

enter image description here

To get the group GUID, you can navigate to https://aad.portal.azure.com/ and click Azure Active Directory > Groups > Click on your group. The guid is located in the "Object Id". field:

enter image description here

  • 1
    Exactly what I was looking for and worked perfectly for what I needed. Thanks for the help.
    – Martin
    Mar 29, 2021 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.