Gets the colleagues for the specified user 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:

 
 
##Gets the colleagues for the specified user using SharePoint 2010 web service in powershell
$uri="http://serverName:10736/sites/ECT2/_vti_bin/UserProfileService.asmx?wsdl"
## $accountName is a string that contains the account name for which you need to get all the colleagues
$accountName="domainName\userName"


## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
$userProfileWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
$colleagues=$userProfileWebServiceReference.GetUserColleagues($accountName)

## Creates an GetUserColleagues.xml file in the D:\ which contains colleague information for the specified $accountName
$output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\GetUserColleagues.xml", $false
$output.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
$output.WriteLine("<Colleagues>")
foreach($colleague in $colleagues)
{
$accountName=$colleague.AccountName
$privacy=$colleague.Privacy
$name=$colleague.Name
$isInWorkGroup=$colleague.IsInWorkGroup
$group=$colleague.Group
$email=$colleague.Email
$title=$colleague.Title
$url=$colleague.Url
$userProfileId=$colleague.UserProfileId
$id=$colleague.Id
$output.WriteLine("<Colleague AccountName=""$accountName"" Privacy=""$privacy"" Name=""$name"" IsInWorkGroup=""$isInWorkGroup"" Group=""$group"" Email=""$email"" Title=""$title"" Url=""$url"" UserProfileId=""$userProfileId"" Id=""$id"" >")
$output.WriteLine("</Colleague>")
}
$output.WriteLine("</Colleagues>")
$output.WriteLine()
$output.Dispose()


Output:

output.jpg



Ebook Download
View all
Learn
View all