What PowerShell can grant a specific user Admin permissions on ALL site collections in SharePoint Online?

frob 4,261 Reputation points
2021-12-22T00:22:39.467+00:00

Hi there

What PowerShell can grant specific user Admin permissions on ALL site collections in SharePoint Online?

Thank you.

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. JoyZ 18,111 Reputation points
    2021-12-22T02:08:25.2+00:00

    @frob ,

    SharePoint Online PowerShell to add a site collection administrator for all site collections:

    #Variables for processing  
    $AdminURL = "https://tenant-admin.sharepoint.com/"  
    $AdminName = "******@tenant.onmicrosoft.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  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,931 Reputation points
    2021-12-22T12:02:56.44+00:00

    Hi @frob

    Use the Set-SPOUser cmdlet to configure the properties of an existing user. That is, to add or remove a user as a SharePoint Online site collection administrator.

    You must have the SharePoint Online Administrator or Global Administrator role to run the cmdlet.

    For permissions and the most current information about Windows PowerShell for SharePoint Online, see the online documentation.
    https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/introduction-sharepoint-online-management-shell?view=sharepoint-ps

    Set-SPOUser
    https://learn.microsoft.com/en-us/powershell/module/sharepoint-online/set-spouser?view=sharepoint-ps

    Hope this resolves your Query!!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.