SharePoint Online: Add Site Collection Administrator using PowerShell
Requirement: Add Site Collection Administrator in SharePoint Online.
Site Collection Administrator in SharePoint Online
SharePoint site collection administrators have full access rights to manage all sites under a site collection. When creating a site collection, a Global Administrator or SharePoint Online Administrator specifies the primary site collection administrator for the site. Unlike SharePoint on-premises, a SharePoint Online site collection can have several administrators but only one primary administrator.
It is possible to add multiple site collection admins for any SharePoint site collection. To add another site collection administrator in SharePoint Online, you must have one of the Global Administrator, SharePoint Online administrator, or Site Collection Administrator roles of the particular site.
In this article:
- Site Collection Administrator in SharePoint Online
- How to add a site collection administrator in SharePoint Online?
- Add Site Collection Administrator in Modern / Group Connected SharePoint Online Sites:
- PowerShell Script to Add Site Collection Administrator in SharePoint Online:
- Add Site Collection Admin to All SharePoint Online Sites using PowerShell:
- Change Primary Site Collection Administrator using PowerShell:
- Add Site Collection Administrator to Group/Modern Sites
- Add Site Collection Administrator using PowerShell CSOM:
- PnP PowerShell to Add Site Collection Administrator in SharePoint Online
- Add Site Collection Administrator to All Sites in the Tenant
How to add a site collection administrator in SharePoint Online?
How do I add a collections admin in SharePoint Online? There are a few different ways that you can add a site collection administrator to your SharePoint Online environment. The easiest way is to use the SharePoint Admin site:
Grant Site Collection Administrator Rights through SharePoint Admin Center
To add a user to the site collection administrator in SharePoint Online through SharePoint Admin Center, do the following:
- Navigate to your SharePoint Admin Center >> Click on Active Sites (E.g., https://Crescent-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx)
- Select the site collection, click on the “Permissions” button from the command bar, and then click on the “Manage Admins” menu item.
- This brings the “Manage admins” page, where you can add multiple site collection administrators. Moreover, it provides the option to change the primary site collection administrator. From there, you can add or remove administrators as needed.
- Once you have added the new user, press Save to commit the changes, and any new Site Collection Administrator will have full control to the root site and any subsite within that Site Collection.
On Group site collections, The Office 365 Group owners are set as site collection administrators by default. You can add a new site collection Admin to the group owner or under additional site owners.
Add user as site collection administrator via site settings
How to add a user to the site collection administrator in SharePoint Online? When you create a new SharePoint Online site, You’ll be entering the “Primary Administrator” or the SharePoint site owner, who’ll automatically become a site collection admin. Once the site collection is created, You can also navigate to the site >> Click on the Settings gear icon >> Site Settings >> Site collection administrators link to add additional site collection administrators. Direct link: https://tenant.sharepoint.com/sites/siteurl/_layouts/15/mngsiteadmin.aspx
Enter the name or email address of the person you want to add as an administrator. Once you’ve added the administrator, they will be able to access all site collection content, features, and settings. If you need to add multiple administrators, you can do so by separating their names or addresses with a semicolon. Click on “OK” once done.
Relatively easy, isn’t it? Well, It’s easy for one single site collection. However, there is a problem when you have a large number of site collections. Say you have 100s of SharePoint Online site collections; you can’t simply select all of your site collections and add a site collection administrator to all of them in one shot! So, let’s see how to add a site collection administrator in SharePoint Online using PowerShell.
What is the difference between a site collection administrator and a site owner?
- The site owner may have full control only over a specific site, whereas the site collection administrator will have full control to all the sites and subsites of the site collection.
- The primary site collection administrator receives administrative email alerts, such as storage notifications for the site collection.
- Site collection Admins will have access to site collection level features, such as site collection recycle bin, site collection features, etc.
- A site owner cannot remove a site collection administrator, whereas the opposite is possible.
- Site Collection Admin can access any item with unique permission. But the site owner can’t do so.
Add Site Collection Administrator in Modern / Group Connected SharePoint Online Sites:
The “Site collection Administrators” link in the site settings page is hidden in group-connected modern team sites. By default, the Office 365 Group Owner is configured as the site collection administrator. So, you can add any user to the owners group of the Office 365 group in order to make them site collection administrators, or use the below steps to add additional site collection admins.
- Click on Settings gear >> Site Permissions >> Click on “Advanced permissions settings”
- Click on the “Site Collection Administrators” button in the ribbon.
Anyway, In SharePoint Online, site collection administrators are to be added on a site collection-by-site collection basis, as there are no web application level user policies that can be set from Central Administration as we do in SharePoint on-premises. So, the solution is: Use PowerShell to add a site collection administrator in SharePoint Online!
PowerShell Script to Add Site Collection Administrator in SharePoint Online:
How do I add a site collection administrator in SharePoint online using PowerShell? Here is the PowerShell for SharePoint Online to add a site collection administrator using the Set-SPOUser cmdlet with SharePoint Online Management Shell:
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "salaudeen@crescent.onmicrosoft.com"
$SiteCollURL = "https://crescent.sharepoint.com/sites/Sales/"
$SiteCollectionAdmin = "mark@crescent.onmicrosoft.com"
#User Name and Password to connect
#$SecurePWD = read-host -assecurestring "Enter Password for $AdminName"
$SecurePWD = ConvertTo-SecureString "Password1" -asplaintext -force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePWD
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential
#Add Site collection Admin
Set-SPOUser -site $SiteCollURL -LoginName $SiteCollectionAdmin -IsSiteCollectionAdmin $True
This PowerShell also works when you want to add a group as a site collection administrator in SharePoint Online.
Add Site Collection Admin to All SharePoint Online Sites using PowerShell:
SharePoint Online PowerShell to add a site collection administrator for all site collections.
#Variables for processing
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "SPAdmin@Crescent.com"
#User Names Password to connect
$Password = Read-host -assecurestring "Enter Password for $AdminName"
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential
$Sites = Get-SPOSite -Limit ALL
Foreach ($Site in $Sites)
{
Write-host "Adding Site Collection Admin for:"$Site.URL
Set-SPOUser -site $Site -LoginName $AdminName -IsSiteCollectionAdmin $True
}
How about adding a site collection administrator to multiple sites in bulk? Sure! You can use a CSV file input and add site admin to multiple sites: How to Add Site Collection Admin to Multiple Sites from a CSV using PowerShell?
Change Primary Site Collection Administrator using PowerShell:
Here is the SharePoint Online PowerShell to set site collection administrator using the Set-SPOSite cmdlet.
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "salaudeen@crescent.onmicrosoft.com"
$SiteCollURL = "https://crescent.sharepoint.com/sites/Sales"
$NewSiteAdmin = "mark@crescent.onmicrosoft.com"
#User Names Password to connect
$SecurePWD = ConvertTo-SecureString "Password1" -asplaintext -force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePWD
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential
#Change Site Collection Primary Admin
Set-SPOSite -Identity $SiteCollURL -Owner $NewSiteAdmin -NoWait
Add Site Collection Administrator to Group/Modern Sites
Here is the script to use in “SharePoint Online Management Shell” to add site collection admins to all sites, including Modern Team sites.
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName="SPAdmin@crescent.com"
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential (Get-Credential)
#Get All Site Collections
$AllSites = Get-SPOSite -Limit ALL
#Loop through each site and add site admins
Foreach ($Site in $AllSites)
{
Write-host "Adding Site Collection Admin for:"$Site.URL
Set-SPOUser -site $Site.Url -LoginName $AdminName -IsSiteCollectionAdmin $True
}
You can apply a filter to site collections to get all site collections of a specific type. E.g., To get all communication sites, use:
Get-SPOSite -Template SITEPAGEPUBLISHING#0
Similarly, you can filter site collections and add site collection admins as:
$Sites = Get-SPOSite -Limit All | Where {$_.Url -like 'https://crescent.sharepoint.com/sites/Project*'}
Add Site Collection Administrator using PowerShell CSOM:
Besides SharePoint Online Management Shell, we can also use the PowerShell CSOM method to add a user to the site collection administrator group. Here is how:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/marketing"
$UserAccount="i:0#.f|membership|Salaudeen@crescent.com"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#sharepoint online powershell set site collection administrator
$User = $Ctx.Web.EnsureUser($UserAccount)
$User.IsSiteAdmin = $True
$User.Update()
$Ctx.ExecuteQuery()
PnP PowerShell to Add Site Collection Administrator in SharePoint Online
You need to give yourself access to every site collection individually to access it. If there are hundreds of them, rather than adding to each site, you can use the PowerShell cmdlet Add-PnPSiteCollectionAdmin to do that. Here is how to add a user as a site collection administrator using PnP PowerShell:
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#add user as site collection administrator powershell sharepoint online
Add-PnPSiteCollectionAdmin -Owners "Salaudeen@crescent.com"
Existing site collection admins stay as is! To add more than one site collection admin, use:
Add-PnPSiteCollectionAdmin -Owners "Salaudeen@crescent.com", "Charles@crescent.com"
You can also add site collection admin using the PnP PowerShell cmdlet Set-PnPTenantSite as:
#Set Runtime Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteUrl="https://crescent.sharepoint.com/sites/jackson"
$SiteCollAdmin="salaudeen@crescent.is"
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Add Site collection Admin user permission
Set-PnPTenantSite -Url $SiteUrl -Owners $SiteCollAdmin
Add Site Collection Administrator to All Sites in the Tenant
To Add a Site Collection Administrator to All Site Collections in the tenant, use
#Parameters
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$SiteCollAdmin="salaudeen@crescent.com"
#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Interactive
#Get All Site collections and Iterate through
$SiteCollections = Get-PnPTenantSite
ForEach($Site in $SiteCollections)
{
#Add Site collection Admin
Set-PnPTenantSite -Url $Site.Url -Owners $SiteCollAdmin
Write-host "Added Site Collection Administrator to $($Site.URL)"
}
Add Site Collection Admin to All OneDrive Sites using PnP PowerShell
Similarly, to add a site collection administrator to all OneDrive sites, use:
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com"
$AdminName = "Salaudeen@crescent.com"
#Connect to SharePoint Online Admin Center
Connect-PnPOnline -url $AdminCenterURL -Interactive
#Get all OneDrive Site colections
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
Foreach ($Site in $OneDriveSites)
{
Write-host "Adding Site Collection Admin for:"$Site.URL
Set-PnPTenantSite -Url $Site.Url -Owners $AdminName
}
Have you added someone by mistake? Want to remove an existing site collection admin from SharePoint Online? Well, You can remove a SharePoint Online site collection administrator either from a single site or all sites: SharePoint Online: Remove Site Collection Administrator using PowerShell
Related Articles:
- Change Owner/Add Site Collection Administrator to OneDrive for Business Site using PowerShell
- Site Collection Administrators Report for All SharePoint Sites
- Remove site collection administrator in SharePoint 2016 using PowerShell
- Change Site Collection Primary, Secondary Administrators in SharePoint
You can use the PowerShell scripts to get a list of site collection administrators either from a single site or from all sites in your Microsoft 365 environment.
More info: Get all site collection administrators using PowerShell in SharePoint Online
No! The global admin or tenant administrator doesn’t get access to the SharePoint Online site automatically until you add them to the site.
To make someone a SharePoint admin in Office 365, You have to assign users with a SharePoint admin role through the Microsoft admin center.
More info: How to grant access to SharePoint Online administration center?
A few different methods are available to remove a site collection Admin in SharePoint Online: The first one is to use the web browser interface to remove the site collection admin from the site settings page. The next method you can use is through the SharePoint Online admin center. Finally, you can use PowerShell to remove a site collection administrator.
More info: How to Remove site collection administrator in SharePoint online using PowerShell?
You just saved me hours of manual administrator entry, thank you so much!
<3
Thank you!!
Very happy!!! 😀
How to remove site collection administrators in sharepoint online using powershell.
Refer: Remove Site Collection Administrator in SharePoint Online using PowerShell
Note: Get-SPOSite does not return sites created by O365 Groups (& Planner) or Teams, unless you specifically specify the URL of the site… so no enumeration of those sites 🙁
Not true. Get-SPOSite does get me SP Sites that belong to an Office Group
A lot can change in a year and two months.