Skip to content

Adding Site Collection Administrators Programmatically

December 19, 2011

When creating new site collections in SharePoint you must select a Site Collection Administrator, and possibly add a secondary administrator.  For cases where you want to have more administrators, you can easily enough add more users manually.

Here is PowerShell function that adds a user to the owners group and also to Site Collection Administrators.  The function uses the get-SPClaim function from the previous post for Claims-based scenarios.  I include the function here as well for completeness.

$m = [Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager]::Local
Add-PSSnapin Microsoft.SharePoint.PowerShell -ea silentlycontinue 
Function Get-SPClaim {
    param ([string]$user)
    $claim = New-SPClaimsPrincipal -identity $user -IdentityType "WindowsSamAccountName"
    return $m.EncodeClaim($claim)
Function Set-Owner() {
    param ([string]$login,

    $owner = get-SPClaim($login)
    $sca = $web.EnsureUser($owner)
    $sca.IsSiteAdmin = $true
    $group = $web.AssociatedOwnerGroup

One can reasonably assume that the property to control SCAs is part of the SPSite object, but then one would be wrong.  Despite the hard limit of the creation functionality, both Form and Function [sic], the inherit design is the reverse.  The property exists in SPUser and scoped to the root web (the property is named IsSiteAdmin.)  Needs some mental gymnastics, but it works…

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: