Add User to Farm admin group PS script

I wrote a little script in PowerShell to add users to the Farm Administrator group of a SharePoint environment. You can easily customize this script for other SharePoint groups or import users from a CSV file to import multiple users into a SharePoint Group.

# <# # .DESCRIPTION #		Add users to the Farm Administrators group # # .INPUT #		- Central Admin port number #		- user or group #		- http Central admin URL # # .NOTES #		File Name	: Add_user_farm_admin_group.ps1 #		Author		: Ronald Bruinsma @ #		Requires	: PowerShell Version 2.0 #		Date		: 02/02/2011 # .LINK #		This script posted to: # # # #>
# ##
# # Start of script
# ##

#Include the SharePoint cmdlets:
#Add-PsSnapin Microsoft.SharePoint.PowerShell

Write-Host 'Add user(s) to Farm Administrator group:'
Write-Host '----------------------------------------'

# input:
$caPortNumber =  Read-Host -Prompt 'Port number of Central Admin site'
$URL = Read-Host -Prompt 'URL of the Central Admin site'
	$userToAdd =  Read-Host -Prompt 'User to add to Farm Admin group '

	#create a website object:
	$site = new-Object Microsoft.SharePoint.SPSite("http://"+$URL+":"+$caPortNumber)
	$web = $site.RootWeb

	#get the Farm administrators group:
	$farmadministrators = $web.SiteGroups["Farm Administrators"]

	#add the user to the Farm administartor group:
	$farmadministrators.AddUser($userToAdd,"","New Sharepoint Farm Admins","")

	#round up
	Write-Host '----------------------------------------'
	Write-Host "Succesfully added " $userToAdd " to the Farm administrator group on the CA site: " $URL":"$caPortNumber
	Write-Host '----------------------------------------'
	Write-Host 'Current users in Farm Administrator group:'
	foreach ($user in $farmadministrators.users)
	Write-Host $user
	Write-Host '----------------------------------------'

	# Add another user to the Farm Administrator group? if yes, start all over again.
    $addAnotherUser = Read-Host 'Add another user to the Farm Administrator group? (Y/N)'
# if no, than quit the script
until ($addAnotherUser -eq 'N')

#dipose everything:

6 thoughts on “Add User to Farm admin group PS script

  1. Thats a nice script. Good idea. But something went wrong for me. At the part $farmadministrators.AddUser($userToAdd) I receive an error.

    PS C:> $farmadministrators.AddUser($userToAdd)
    Cannot find an overload for “AddUser” and the argument count: “1″.
    At line:1 char:28

  2. CHris, did you include the SharePoint cmdlets?

    #Include the SharePoint cmdlets:
    #Add-PsSnapin Microsoft.SharePoint.PowerShell

    Or start this script in the SharePoint powershell?

  3. Fixed it ;-)


    “Name” is a required field so you have to change the script and fill out the name tag.
    If you open the Farm Admin group and try to add a user you’ll see the required field :-)

    $farmadministrators.AddUser($userToAdd,””,”New Sharepoint Farm Admins”,””)


  4. I think it is better to write the followed because the value of $userToAdd can be used for the Name value too ;-)


    So the User/Group you added to the $userToAdd value is also valid for the Name.

    In my case the result is the following after run the script.

    Accountname: MainDomainDomain Admins
    Name: Domain Admins

    All fine now ;-)


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>