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.
  1. "https://<tenant>-my.sharepoint.com/_layouts/15/MyQuickLinks.aspx"
Below is the OnPrem Path.
  1. https://<tenant>.sharepoint.com/_layouts/15/MyQuickLinks.aspx
The below code retrieves quicklinks from user profile for the specified user account and exports the resulting data to a CSV File.
Code Usage
  1. ##Create an empty System.Array object
  2. $QuickLinksArray = @()
  3. ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
  4. $uri="http://<site>/_vti_bin/UserProfileService.asmx?wsdl"
  5. ## if you are executing this code in a Virtual Machine it's default credentials will be used to connect to proxy.
  6. $userProfileDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
  7. ##Get quick links for the specified user account.
  8. $userLinks = $userProfileDataServiceWebServiceReference.GetUserLinks("domain\accountid")
  9. ##Iterate on the comments collection and store the value in PageNoteBoardComments array collection.
  10. foreach($item in $userLinks)
  11. {
  12. $QuickLinksArray += New-Object
  13. PsObject -property @{
  14. 'URL' = [string]$item.Url
  15. 'Name' = [string]$item.Name
  16. 'Privacy' = [string]$item.Privacy
  17. 'Group' = [string]$item.Group
  18. 'ID' = $item.ID
  19. }
  20. }
  21. ##Finally, use Export-Csv to export the data to a csv file
  22. $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.
  1. #Path to the CSV output path file.
  2. $CSVOutputfilepath = "D:\XXXX\GetMyLinks.csv"
  3. #Path to the log file.
  4. $outputfilepath = "D:\XXXX\GetMyLinksLogs.txt"
  5. #Excel File path.
  6. $FilePath = "D:\XXXX\userlist.xls"
  7. #Create an empty System.Array object
  8. $QuickLinksArray = @()
  9. # Create an Object Excel.Application using Com interface
  10. $objExcel = New-Object -ComObject Excel.Application
  11. # Disable the 'visible' property so the document won't open in excel
  12. $objExcel.Visible = $False
  13. # Open the Excel file and save it in $WorkBook
  14. $WorkBook = $objExcel.Workbooks.Open($FilePath)
  15. # Load First sheet
  16. $sheet = $WorkBook.Worksheets.Item(1)
  17. #Find PageUrl and get the column position
  18. $pageurlcolumns = $sheet.UsedRange.Columns.Find('Title').Column
  19. #Get all the Rows within Excel
  20. $rows = $sheet.UsedRange.Rows.Count
  21. ## Get Page Number Count
  22. $count = 1;
  23. ## Get number of user in excel
  24. $rowCount = $rows - 1
  25. "-"*80 | Write-Host
  26. Write-Host -ForegroundColor Green "Total number of account's initiated : " $rowCount
  27. Write-Host -ForegroundColor Green "Started at : $((Get-Date).ToString())"
  28. "-"*80 | Write-Host
  29. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  30. "Total number of account's initiated : " + $rowCount | Out-File -Encoding Ascii -append $outputfilepath
  31. "Started at :" + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
  32. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  33. for ($i=2; $i -le $rows; $i++)
  34. {
  35. try{
  36. #Get PageUrl column values - Eg: Domain\accountID
  37. $accountID = $sheet.Cells.Item($i, $pageurlcolumns).text
  38. #Log Account ID
  39. Write-Host -ForegroundColor Green "$count : " $accountID
  40. "$count : " + $accountID | Out-File -Encoding Ascii -append $outputfilepath
  41. ## Get path of user profile webservice file
  42. $uri = "http://<site>/_vti_bin/UserProfileService.asmx?wsdl"
  43. ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
  44. $userProfileServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
  45. ## Retrieve user links by account name
  46. $quickLinksOnAccountID = $userProfileServiceWebServiceReference.GetUserLinks($accountID)
  47. foreach($item in $quickLinksOnAccountID)
  48. {
  49. $QuickLinksArray += New-Object PsObject -property @{
  50. 'ID'= $item.ID
  51. 'Name' = [string]$item.Name
  52. 'URL' = [string]$item.Url
  53. 'Group' = [string]$item.Group
  54. 'Privacy' = [string]$item.Privacy
  55. 'UserLoginID' = [string]$accountID
  56. }
  57. ##Add comments for a specific page.
  58. #$WriteCommentsOnUrl = $socialDataServiceWebServiceReference.AddComment($url,$item.Comment,0,"TestMultiline")
  59. }
  60. $count++
  61. }
  62. catch{
  63. Write-Host -ForegroundColor Green "$count : $accountID : " $_.Exception.Message
  64. "$accountID : " + $_.Exception.Message | Out-File -Encoding Ascii -append $outputfilepath
  65. }
  66. }
  67. #Finally, use Export-Csv to export the data to a csv file
  68. $QuickLinksArray | Export-Csv -NoTypeInformation -Path $CSVOutputfilepath
  69. "-"*80 | Write-Host
  70. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  71. Write-Host -ForegroundColor Green "Completed at : $((Get-Date).ToString())"
  72. "Completed at : " + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
  73. Write-Host -ForegroundColor Green "Total QuickLinks Found : " $QuickLinksArray.Count
  74. "Total QuickLinks Found : " + $QuickLinksArray.Count | Out-File -Encoding Ascii -append $outputfilepath
  75. "-"*80 | Write-Host
  76. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  77. #Close the workbook object
  78. $WorkBook.close()
  79. #close the excel object
  80. $objexcel.quit()
Please feel free to share your comments.
Hope this helps !!!!