3

Is it possible to add a site collection administrator to all sites under a web application in SharePoint 2007. I can see how to do this for SharePoint 2010 upwards but not 2007. I was hoping to do this via powershell.

Thanks in advance

  • It's been a while, but I would use WebApplication Policy – Matthew McDermott Mar 7 '17 at 20:54
  • @MatthewMcDermott thanks, I did come across this but not sure what the performance hit would be like. I've asked the question in here if you are interested. – Webfort Mar 7 '17 at 21:00
  • Two benefits. Fire and forget. The setting applies today and to any sites created tomorrow. Also, another site collection admin cannot change it. – Matthew McDermott Mar 8 '17 at 13:38
  • So you would say it's ok to do? Ok across all versions of SharePoint 2007 up? – Webfort Mar 8 '17 at 20:28
3

In SharePoint 2007, you have to do little tweak in the blow script. This script set multiple users as Site collection admins for multiple sites.

  • 1st create a text file and write all the site collections url in it.
  • Enter the User name, email id and name in the Target??? variable

Here is code

# For SharePoint 2007 compatibility 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

# Get the user credentials here. Replace below ones with the corresponding 
# value for the user 
$TargetUserDomainID = "contoso\parkumar", "adprod\kbhanu", "contoso\mideshmu" 
$TargetUserEmail = "pkumar@contoso.com", "KBhanu@contoso.com","mideshmu@contoso.com" 
$TargetUserLogOnName = "Kumar, Paritosh", "Bhanu, Kedar", "Deshmukh, Mihir" 

# Specifies path for text file containing SharePoint site collection urls 
# This file should contain root site paths for site collections 
$Siteslist = Get-Content -Path "D:\Solutions\SitesList.txt" 

# Runs for every site collection 
foreach($Siteurl in $Siteslist) 
{ 
    # Output site collection name and get root site from SharePoint. 
    Write-Output "" 
    Write-Output "Working on site $Siteurl" 
    $Site = New-Object Microsoft.SharePoint.SPSite($SiteUrl) 
    $Web = $Site.Rootweb 

    # Runs for every user 
    for($count = 0; $count -lt $TargetUserDomainID.count ;$count++) 
    { 
        Try 
        { 
            # Add user to the site first and updates site 
            $Web.SiteUsers.Add($($TargetUserDomainID[$count]), $($TargetUserEmail[$count]),$($TargetUserLogOnName[$count]), "") 
            $TargetUser = $web.EnsureUser($($TargetUserDomainID[$count])) 
            $web.Update() 

            # Set user as site collection admin 
            if($TargetUser.IsSiteAdmin) 
            { 
                Write-Host "$($TargetUserLogOnName[$count]) is already added on this site" 
            } 
            else 
            { 
                $TargetUser.IsSiteAdmin = $true 
                $TargetUser.Update() 
                write-host "Added $($TargetUserLogOnName[$count]) as admin" -ForegroundColor Green 
            } 
        } 
        Catch 
        { 
            Write-Host $error[0].Exception.Message -foreground red 
        } 
    }     
} 

Download complete script from here: Add Multiple Users as Site Collection Admin for Multiple Site Collections

  • Thanks. I get this when I try and run it : Exception setting "IsSiteAdmin": "You need to be a site collection administrator to set this property." – Webfort Mar 5 '17 at 12:08
  • Sorted it now. If i wrap the for loop in the following [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ it works. Thanks – Webfort Mar 5 '17 at 12:12

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.