Changing Site Collection Administrators using PowerShell

Site collections can have two administrators and you can modify them through SharePoint Central Administration. But if you need to change these admins using PowerShell script you can use the following PowerShell function. I filtered site collections with the url to find the appropriate site collection. You can define a parameter to this function and pass the site collection or the url of the site collection.

Function ChangeSiteCollectionAdministrators
{
	Write-Host -Foregroundcolor green "- Changing the site collection administrators"
	$site = Get-SPSite | ?{$_.Url -like "*sites/tempSite*"}
	If ($site -ne $null)
	{
		Set-SPSite -Identity $site.Url -OwnerAlias "DOMAIN\farmacc" -SecondaryOwnerAlias "DOMAIN\svcacc" 
		Write-Host -Foregroundcolor white "- Site Collection Administrators for '$site' is changed."
	}
}

 

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: