Add a User and/or Group to all SiteCollections as SiteCollection Admin


This Script will automatically add a User and/Or Group to ALL SiteCollections in ALL WebApplications of your SharePoint Farm.

It can be very easily modified to do this action on just one WebApp  by editing the line

$wapps = Get-SPWebApplication to

$wapps = Get-SPWebApplication "mywebappname" 

 


 

#example: $AccountList = @("DOMAIN\User" , "DOMAIN\Group")

$AccountList = @("domain\myuser")

 

 

$wapps = Get-SPWebApplication

Foreach($webapp in $wapps)

{

  foreach ($SiteCollection in $webapp.Sites)

  {

       write-host $SiteCollection.url

       $spweb = Get-SPWeb $SiteCollection.url

 

       foreach ($Account in $AccountList)

       {

           $user = Get-SPUSER -identity $Account -web $SiteCollection.url -ErrorAction SilentlyContinue

           if ($user -eq $null)

           {

               $SPWeb.ALLUsers.ADD($Account, "", "", "Added by SiteCollectionAdminScript")

               $user = Get-SPUSER -identity $Account -web $SiteCollection.url

               Write-host "Added user $Account to URL $SPWeb.URL" -Foregroundcolor green

           }

            else

           {

                Write-host "user $Account was already in URL " $SPWeb.URL -Foregroundcolor red

           }

           if ($user.IsSiteAdmin -ne $true)

           {

             $user.IsSiteAdmin = $true

             $user.Update()

             Write-host "$account has been made an admin on $SPWeb.URL" -Foregroundcolor green

           }

           else

           {

             Write-host "$account was already an admin on $SPWeb.URL" -Foregroundcolor red

           }

       }     

  }

 }


Comments (2)
  1. Striker says:

    This script ran. I verified the active directory group was in the site collection administrators but the user did not have the rights. I added the exact same group manually and it worked. Any ideas?

  2. Anonymous says:

    This Script Adds users to the Site Collection Admins group, but the Users have no rights when I check their permissions and get "This Site has not been shared with you" screen with SharePoint 2013

Comments are closed.

Skip to main content