Add user collections to the group using SharePoint 2010 web service in powershell


Steps Involved:

  1. Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
  2. Run the following script.

Powershell Script:

 
 
## Add user collections to the group using SharePoint 2010 web service in powershell
$uri="http://serverName:10736/sites/ECT2/_vti_bin/UserGroup.asmx?wsdl"
## $groupName is a string that contains group name in which the user collections has to be added
[
String]$groupName ="Group1";
## $userInfoXmlPath is a string which contains the Users.xml path
## Users.xml contains the information about the users that has to be added to the specified group mentioned in $groupName
$userInfoXmlPath="D:\Users.xml"
$xmlDocument = New-Object -TypeName System.Xml.XmlDocument
$xmlDocument.Load($userInfoXmlPath)
## $userInfoXml is a System.Xml.XmlNode object that specifies one or more user information that has to be added to the specified group
$userInfoXml = $xmlDocument.DocumentElement

## Web Service Reference - http://Site/_vti_bin/UserGroup.asmx
$usergroupWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
$usergroupWebServiceReference.AddUserCollectionToGroup($groupName,$userInfoXml)


Users.xml:

Users.jpg


Result:

Navigate to Site Actions => Site Settings => Users and Permissions => People and Groups => Group1. You could be able to see the user collections added to the group "Group1".

Summary:

Thus in this blog you have seen how to add the user collections to the specified group using SharePoint 2010 web service in powershell.