SharePoint Add Site collection administrator

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

param
(
[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;
$userToBeMadeSiteCollectionAdmin.Update();
Write-Host "User is now site collection admin for $siteCollection" -ForegroundColor Green;
}
else
{
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;
}
}
else
{
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!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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