Forum Discussion
jean090681
Aug 21, 2019Copper Contributor
Add AD Security group as Site collection administrator - SPO
Is there a way to add a security group as Primary or secondary site collection administrator to all the sites in the tenant via PowerShell? I know this works for adding a user account to all the ...
- Aug 21, 2019That's not correct...you can add an AD Security Group as site collection admins with no problems and it can be also done through PS: https://kirkbarrett.wordpress.com/2016/04/04/adding-an-o365-security-group-to-the-site-collection-administrators-group/
Steven Niedermeyer
Aug 27, 2021Copper Contributor
jean090681 - you can also use PNP as suggested by Murilo Santana on StackExchange:
https://sharepoint.stackexchange.com/questions/268250/add-ad-security-group-as-site-collection-administrator-spo
I modified the original script to the one below. You must be a Site Collection Admin to run the Add-PnPSiteCollectionAdmin command. Use Set-PnPTenantSite -Owners if you are not an Admin for the site but have the SharePoint admin role.
Connect-PnPOnline -url "https://tenant.sharepoint.com/sites/SiteCollection"
$web = Get-PnPWeb
$admins = Get-PnPSiteCollectionAdmin
write-host "Original Site Colletion Admins: " $admins
$azureADGroup = "c:0t.c|tenant|AzureAD-SecurityGroup-ID"
$ensureUser = $web.EnsureUser($azureADGroup)
$user = Get-PnPUser -Identity $azureADGroup
Add-PnPSiteCollectionAdmin -Owners $user.LoginName
Start-Sleep -s 5
$admins = Get-PnPSiteCollectionAdmin
write-host "New Site Collection Admins: " $admins(