Grant a Security Group SharePoint Online Library Permissions with PowerShell
Question details
Grant an Active Directory security group a custom permission level on a SharePoint Online library using PowerShell.

- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- An administrator wants to manage library access through an Active Directory security group.
- Observed behavior
- The SharePoint Online Management Shell cannot directly resolve the security group in every scenario.
Confirm that the AD security group is synchronized to Microsoft Entra ID, and obtain its Entra object ID. You also need permission to manage the library, an existing SharePoint group and custom permission level, and an app registration configured for PnP PowerShell authentication.
Assign library access through a SharePoint group with PnP PowerShell
Use this approach when the security group cannot be resolved directly by the SharePoint Online Management Shell.
The commands add the Entra security group to an existing SharePoint group, then grant that SharePoint group a custom permission level on the library.
Copying inherited permissions preserves existing access when inheritance is broken. Review those assignments afterward if the library should have more restrictive access.
In PowerShell 7, install PnP PowerShell if needed with Install-Module PnP.PowerShell, then connect using Connect-PnPOnline -Url 'https://contoso.sharepoint.com/sites/SiteName' -Interactive -ClientId '<app-client-id>'. Replace the site URL and client ID with your values.
Run Add-PnPGroupMember -Identity 'Library Access' -LoginName 'c:0t.c|tenant|<group-object-id>'. Replace Library Access with the existing SharePoint group name and <group-object-id> with the synchronized security group's Microsoft Entra object ID.
Run Set-PnPList -Identity 'Documents' -BreakRoleInheritance -CopyRoleAssignments, replacing Documents with the library name. Skip this step if the library already has unique permissions.
Run Set-PnPListPermission -Identity 'Documents' -Group 'Library Access' -AddRole 'Custom Permission'. Replace the library, SharePoint group, and role names with your existing names.
Open the library in SharePoint and go to Settings > Library settings > Permissions for this document library. Confirm the group and permission level, and review any copied assignments.

Work with SharePoint library documents in WPS Office
WPS Office is a free, lightweight alternative for working with Office documents in a familiar interface. Its format compatibility helps you move existing files into your workflow, though SharePoint permissions must still be managed in SharePoint.

Frequently Asked Questions
Does the Active Directory group need to be synchronized?
Yes. For SharePoint Online to recognize the group, synchronize the AD security group to Microsoft Entra ID and use its Entra object ID in the group claim.
Will breaking inheritance remove existing library permissions?
The example uses -CopyRoleAssignments to retain inherited assignments when inheritance is broken. Review them under Library settings > Permissions for this document library.
Where do I create the custom permission level?
In the SharePoint site, open Site settings > Site permissions > Permission Levels. Create the level before using its name with Set-PnPListPermission.
Can adding the security group grant access elsewhere?
Yes. Members receive the access already assigned to the SharePoint group as well as the library permission added here. Review the SharePoint group's existing permissions before adding the security group.




