2

I'm a global admin in Office 365. I can use the SharePoint Admin Portal to update the site collection admins for existing sites.

However, if I try to do this in PowerShell using Set-SPOSite I get an error saying

I'm not the site collection administrator.

I have hundreds of test site collections that have been created by other global admins. It will be very tedious if I have to add myself as a site collection administrator to each of these through the admin portal.

Is there a way for a global administrator to take control of a site collection using PowerShell?

2

Below is a Powershell script to use in "SharePoint Online Management Shell" for adding site collection admins for ALL site collections:

$AdminLogin = "adminlogin"
$Sites = Get-SPOSite -Limit ALL

Foreach ($Site in $Sites)
{
    Set-SPOUser -site $Site.Url -LoginName $AdminLogin -IsSiteCollectionAdmin $True
}
  • This does not work if you are not already a site collection administrator, even if you are a global administrator. – Ivan Wilson Apr 22 '18 at 23:34
2

You can remove site collection admin from All Site Collection and then add site collection admin to ALL SharePoint online site collection .

For remove site collection admin :

Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking



#Variables for processing

$AdminURL = "https://crescent-admin.sharepoint.com/"

$AdminAccount="salaudeen@crescent.com"



#Connect to SharePoint Online

Connect-SPOService -url $AdminURL -credential (Get-Credential)



#Get All Site Collections

$Sites = Get-SPOSite -Limit ALL



#Loop through each site and add site collection admin

Foreach ($Site in $Sites)

{

    Write-host "Scanning site:"$Site.Url -f Yellow

    #Get All Site Collection Administrators

    $Admins = Get-SPOUser -Site $site.Url | Where {$_.IsSiteAdmin -eq $true}



    #Iterate through each admin

    Foreach($Admin in $Admins)

    {

        #Check if the Admin Name matches

        If($Admin.LoginName -eq $AdminAccount)

        {

            #Remove Site collection Administrator

            Write-host "Removing Site Collection Admin from:"$Site.URL -f Green

            Set-SPOUser -site $Site -LoginName $AdminAccount -IsSiteCollectionAdmin $False

        }

    }

}

For Add site collection admin :

#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

}

Reference :

http://www.sharepointdiary.com/2017/02/sharepoint-online-remove-site-collection-administrator-using-powershell.html

http://www.sharepointdiary.com/2015/08/sharepoint-online-add-site-collection-administrator-using-powershell.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.