Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add user to SharePoint 2010 group using powershell

We need to add several users to several SharePoint Groups.

Does anyone have an example of how to add a user to a sharepoint group using power shell.

like image 695
Shiraz Bhaiji Avatar asked Aug 11 '10 12:08

Shiraz Bhaiji


People also ask

How do I add a bulk user to a SharePoint group?

There is no command to add bulk external users to a SharePoint site. We can add external users one by one via Site settings > People and Groups > Site members > New. After they access the site, their accounts list in Site Member.


2 Answers

To add multiple users to multiple groups, you could use a longer script:

Function AddUsers($userArray, $webUrl)
{
    foreach ($user in $userArray)
    {
        $username = $user[0];
        foreach ($group in $user[1])
        {
            Set-SPUser -Identity $username -Web $webUrl -Group $group
        }
    }
}



$userArray = @(
    @("domain\user1", @("Site Visitors", "Designers")),
    @("domain\user2", @("Site Visitors", "Designers")),
    @("domain\user3", @("Site Owners"))
    )

#Call function without brackets
AddUsers $userArray "http://my-sharepoint-site/"
like image 183
Christian Nesmark Avatar answered Oct 06 '22 02:10

Christian Nesmark


Try this PowerShell script:

Set-SPUser -Identity 'fun/factory' -Web http://someserver -Group 'Name of group'
like image 40
Gaotter Avatar answered Oct 06 '22 02:10

Gaotter