Skip to content

Instantly share code, notes, and snippets.

@sweeneyrobb
Last active August 29, 2015 14:06
Show Gist options
  • Save sweeneyrobb/aa2ea87846f7ad303b5c to your computer and use it in GitHub Desktop.
Save sweeneyrobb/aa2ea87846f7ad303b5c to your computer and use it in GitHub Desktop.
Easy way to add a user as an administrator. Grants Farm Administrator rights along with ShellAdmin for Central Administration and a specified url.
$username = "{username}"
$webAppUrl = "{url}"
$centralAdmin = Get-SPWebApplication -IncludeCentralAdministration | ?{$_.DisplayName -eq "SharePoint Central Administration v4"}
$caWeb = Get-SPWeb -Identity $centralAdmin.Url
$farmAdministrators = $caWeb.SiteGroups["Farm Administrators"]
$farmAdministrators.AddUser($username, "", $username, "Configured via PowerShell")
$db = $centralAdmin.ContentDatabases[0]
Add-SPShellAdmin -UserName $username -database $db
Get-SPWebApplication $webAppUrl | Get-SPContentDatabase | ForEach-Object {
Add-SPShellAdmin -UserName $username -database $_
}
Add-SPShellAdmin -UserName $username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment