Add a user as site collection admin on all site collections using Powershell - SharePoint 2013

SR VSP 1,251 Reputation points
2023-01-10T15:10:02.457+00:00

Team,

Do you have a PS script to Add a user as site collection admin on all site collections in SharePoint 2013 please advise.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,269 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,991 questions
{count} votes

Accepted answer
  1. Xyza Xue_MSFT 28,051 Reputation points Microsoft Vendor
    2023-01-11T07:46:57.98+00:00

    After my research and testing, you can use this powershellTto add a user as site collection admin on all site collections in sharepoint 2013.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
    #User Account to add as Site Collection Admin
    $UserAccount="xyza\spsite"
     
    Get-SPSite -Limit "All" | ForEach-Object {
    $User = $_.RootWeb.EnsureUser($UserAccount)
        if($User.IsSiteAdmin -ne $True)
        {
            $User.IsSiteAdmin = $True
            $User.Update()
            Write-Host "Added Site Collection Administrator for Site Collection:" $_.URL -ForegroundColor Green
        }
        else
        {
            Write-Host "User is already an Site Collection Administrator for Site Collection:" $_.URL -ForegroundColor Yellow
        }
    }
    
    
    

    The running effect is as follows:

    User's image


    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.


2 additional answers

Sort by: Most helpful
  1. Simon Doy 6 Reputation points MVP
    2023-01-10T17:41:29.217+00:00
    1 person found this answer helpful.

  2. Xyza Xue_MSFT 28,051 Reputation points Microsoft Vendor
    2023-01-11T07:38:19.4033333+00:00

    Hi @

    After my research and testing, you can use this powershellTto add a user as site collection admin on all site collections in sharepoint 2013.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
    #User Account to add as Site Collection Admin
    $UserAccount="xyza\spsite"
     
    Get-SPSite -Limit "All" | ForEach-Object {
    $User = $_.RootWeb.EnsureUser($UserAccount)
        if($User.IsSiteAdmin -ne $True)
        {
            $User.IsSiteAdmin = $True
            $User.Update()
            Write-Host "Added Site Collection Administrator for Site Collection:" $_.URL -ForegroundColor Green
        }
        else
        {
            Write-Host "User is already an Site Collection Administrator for Site Collection:" $_.URL -ForegroundColor Yellow
        }
    }
    
    
    

    The running effect is as follows:

    User's image


    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.

    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.