How to create a new Farm Administrator via PowerShell

Today I needed to create a new Farm Administrator and I tried to figured out how to do that simply using PowerShell, aside from creating the user in the directory service, of course. Here is a complete script to gain the result:


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

# Creates a new Farm Administrator

$newFarmAdministrator = Read-Host -Prompt ‘Please provide the name of the new Farm Administrator in the form of DOMAIN\Username’

$caWebApp = Get-SPWebApplication -IncludeCentralAdministration | where-object {$_.DisplayName -eq “SharePoint Central Administration v4”}
$caSite = $caWebApp.Sites[0]
$caWeb = $caSite.RootWeb

$farmAdministrators = $caWeb.SiteGroups[“Farm Administrators”]
$farmAdministrators.AddUser($newFarmAdministrator, “”, $newFarmAdministrator, “Configured via PowerShell”)


$caDB = Get-SPContentDatabase -WebApplication $caWebApp
Add-SPShellAdmin -Database $caDB -Username $newFarmAdministrator


The only thing you will need to do is to create the user in your domain, before executing the script.

Moreover, the script adds the user to the group of “Farm Administrators”, configures the user as a member of group WSS_ADMIN_WPG on each and every server of your farm and adds the user to the SharePoint_Shell_Access role of the configuration database, as well as of the Central Administration database.