SharePoint Online – How to add an additional admin to all sites

This is just going to be a very short form example showing some code to add an Additional Admin to every SharePoint online site.


The Code

The code below will find all modern, teams and publishing site collections, it will then loop through them all and add a defined user as an additional admin.

Be sure to change the *orgName* and *emailOfOwnerToAdd* sections to your own details.

Connect-PnPOnline -Url https://*orgName*-admin.sharepoint.com -Credentials (Get-Credential)

$Sites = Get-PnPTenantSite | where {($_.Template -eq "GROUP#0") -or ($_.Template -eq "TEAMCHANNEL#0") -or ($_.Template -eq "SITEPAGEPUBLISHING#0")}

for($x = 0; $x -lt $Sites.Count; $x++) {
    Set-PnPTenantSite -Url $Sites[$x].Url -Owners "*emailOfOwnerToAdd*"
    Write-Host "Updating $($Sites[$x].Title), Site $($x)"
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started