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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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