Search code examples
powershellsharepointoffice365sharepoint-onlineazure-automation

adding office365 group to Sharepoint site collection administrators thorugh Powershell


I am trying to add one of office 365 group as a site collection administrator in SharePoint online site through PowerShell or API but I am not getting any solution for this. i can do it manually from site UI but I want to automate it so looking for Powershell or API. can add through UI


Solution

  • You can use PnP PowerShell cmdlet Add-PnPSiteCollectionAdmin -owners.

    Reference:https://github.com/pnp/powershell/blob/dev/documentation/Add-PnPSiteCollectionAdmin.md

    The things we need to notice is that unlike the documentation said, we need to use the LoginName like i:0#.f|membership|[email protected]

    So for an O365 group, it shall be like c:0o.c|federateddirectoryclaimprovider|<Object ID>

    For Security group it shall be like c:0t.c|tenant|<Object Id>

    You can get the Object ID for group in Azure AD. enter image description here