SharePoint Add Site collection administrator

If you need to add user as a site collection administrator, you can use the following Powershell script:

[Parameter(Mandatory=$true, HelpMessage='username in format DOMAINusername')]
[string]$Username = "",
[Parameter(Mandatory=$true, HelpMessage='url for web application e.g. http://collab')]
[string]$WebApplicationUrl = ""


Write-Host "Setting up user $Username as site collection admin on all sitecollections in Web Application $WebApplicationUrl" -ForegroundColor White;
$webApplication = Get-SPWebApplication $WebApplicationUrl;

if($webApplication -ne $null)

foreach($siteCollection in $webApplication.Sites){
Write-Host "Setting up user $Username as site collection admin for $siteCollection" -ForegroundColor White;
$userToBeMadeSiteCollectionAdmin = $siteCollection.RootWeb.EnsureUser($Username);
if($userToBeMadeSiteCollectionAdmin.IsSiteAdmin -ne $true)
$userToBeMadeSiteCollectionAdmin.IsSiteAdmin = $true;
Write-Host "User is now site collection admin for $siteCollection" -ForegroundColor Green;
Write-Host "User is already site collection admin for $siteCollection" -ForegroundColor DarkYellow;

Write-Host "Current Site Collection Admins for site: " $siteCollection.Url " " $siteCollection.RootWeb.SiteAdministrators;
Write-Host "Could not find Web Application $WebApplicationUrl" -ForegroundColor Red;

To execute it, your user has to be site collection administrator, for me it was very useful, so…

Enjoy it!


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 )

Facebook photo

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

Connecting to %s