Thursday, 24 April 2014

Add SharePoint site collection administrator using PowerShell

Add SharePoint site collection administrator using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$siteURL = "http://sp2010"
$userAccount = "USA/SPadmin"
Start-SPAssignment -Global
#Get the RootWeb
$web= Get-SPWeb $siteURL
#Get the user acount - If doesn't exists add to AD domain
$user = $web.EnsureUser($userAccount)
#Make the user as Site collection Admin
$user.IsSiteAdmin = $true
$user.Update()
#Print a message
Write-host "User: $($userAccount) has been added as site collection administrator!"
Stop-SPAssignment -Global