Powershell script to add a list of users to the site collection administrators group of every site on your SharePoint 2010 farm.

I wanted a way to inject myself as a site collection admin into every site in sharepoint, Note, I’m not talking about the primary/secondary that you can set in Central admin.
I’m talking about that group you can only get to from within each site itself. Or in this case, with the powershell script below…
Note that it takes an array of names – if you have a team of admins or developers that all need access, you can put all their names in the list.

 

Here’s another version of the script, this one also takes an array of top level URL’s

It’s handy if you have lots of url’s on your site and only want to work with a few of them.

 

5 thoughts on “Powershell script to add a list of users to the site collection administrators group of every site on your SharePoint 2010 farm.

  1. Jack this post is the closest i have come to a script i need to write, and i am having trouble getting the if statement right. Maybe you can help?

    Problem: i need a script to go thru all site collections in a farm and do the folllowing:
    1. Set Primary Owner for site collection administrator
    2. Set Secondary Owner for site collection administrator
    3. Remove all other users from site collection admin group for all site collections.

    My current thought is to do something like this:
    $SC1 = “apscsp10admin-d1”
    $SC2 = “apscsp10scadmin-d1”
    $Sites = get-spsite -limit all
    foreach ($site in $Sites)
    {
    Set-SPSite -Identity $site -owneralias $SC1 -SecondaryOwnerAlias $sc2
    { $user = get-spuser -limit all
    if (($user.issiteadmin = true) -and ((-ne $SC1) -or (-ne $SC2)))

    {
    $user.IsSiteAdmin = false;
    $user.Update();
    }

    else
    {
    write host “No Users to remove from this site”
    }
    }
    }

    Any help you could provide on what i am doing wrong would be grateful!

Leave a Reply