I had a requirement to retrieve quick links for a specific user from a user profile service. Though this can be achieved using "Server Side Object Model" it is restricted for some of the companies to run their "SSOM" code on the production environment. Thus, we came up with an idea of creating PowerShell script using CSOM to retrieve quick links using "User Profile Web Service".
Here you will be seeing how to get mysite quicklinks from user profile in SharePoint 2013 using the PowerShell and CSOM for a specific user account using "User Profile WebService" (UserProfileService.asmx)
You can navigate to my site quick links path in SharePoint office 365 site as shown below.
- "https://<tenant>-my.sharepoint.com/_layouts/15/MyQuickLinks.aspx"
Below is the OnPrem Path.
The below code retrieves quicklinks from user profile for the specified user account and exports the resulting data to a CSV File.
Code Usage
- ##Create an empty System.Array object
- $QuickLinksArray = @()
-
- ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
- $uri="http://<site>/_vti_bin/UserProfileService.asmx?wsdl"
-
- ## if you are executing this code in a Virtual Machine it's default credentials will be used to connect to proxy.
- $userProfileDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
-
- ##Get quick links for the specified user account.
- $userLinks = $userProfileDataServiceWebServiceReference.GetUserLinks("domain\accountid")
-
- ##Iterate on the comments collection and store the value in PageNoteBoardComments array collection.
- foreach($item in $userLinks)
- {
-
- $QuickLinksArray += New-Object
- PsObject -property @{
-
- 'URL' = [string]$item.Url
-
- 'Name' = [string]$item.Name
-
- 'Privacy' = [string]$item.Privacy
-
- 'Group' = [string]$item.Group
-
- 'ID' = $item.ID
- }
- }
-
- ##Finally, use Export-Csv to export the data to a csv file
- $QuickLinksArray | Export-Csv -NoTypeInformation -Path "D:\Madhu\Powershell\QuickLinks.csv"
Scenario 2
To retrieve all the user links from user profile based on account name.
Note
All the account name's are under "Title" column in Excel sheet.
Please feel free to share your comments.
Hope this helps !!!!