I had a requirement to retrieve quick links for a specific user from the user profile service in office 365 Sharepoint site (Sharepoint online). I have leveraged "User Profile Web Service"(UserProfileService.asmx) to achieve the same in PowerShell script using CSOM.

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".
The below code reads the account name from an Excel file and retrieves Quicklinks from the user profile for the respective user account and exports the resulting data to a CSV File.
Note
All the account names are under "Title" column in the Excel sheet.

Code Usage
  1. #Path to the CSV output path file.
  2. $CSVOutputfilepath = "D:\Madhu\GetMyLinks.csv"
  3. #Path to the log file.
  4. $outputfilepath = "D:\Madhu\GetMyLinksLogs.txt"
  5. #Excel File path.
  6. $FilePath = "D:\Madhu\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 number of user in excel
  22. $rowCount = $rows - 1
  23. ## tenant admin url
  24. $siteUrl = "https://<tenant>-admin.sharepoint.com"
  25. ## Read sharepoint online loginname
  26. $loginname = "username@<tenant>.onmicrosoft.com"
  27. ## Read password
  28. $pwd = "XXXXXXX"
  29. ## Convert password to secure string.
  30. $securePassword = ConvertTo-SecureString $pwd –AsPlainText -Force
  31. ## Connect to sharepoint online
  32. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $securePassword)
  33. ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
  34. $uri= $siteUrl + "/_vti_bin/UserProfileService.asmx"
  35. ## Disable default credentials
  36. $userProfileServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential False
  37. ## Load online credentials to user profile service.
  38. $userProfileServiceWebServiceReference.Credentials = $credentials
  39. ## Load Uri object
  40. $uriS = New-Object System.Uri($siteUrl)
  41. ## Initiate Cookie container object
  42. $container = New-Object System.Net.CookieContainer
  43. ## Auntenticate and set cookie.
  44. $container.SetCookies($uriS, $credentials.GetAuthenticationCookie($siteUrl))
  45. ## Load cookie container to user profile.
  46. $userProfileServiceWebServiceReference.CookieContainer = $container
  47. "-"*80 | Write-Host
  48. Write-Host -ForegroundColor Green "Total number of account's initiated : " $rowCount
  49. Write-Host -ForegroundColor Green "Started at : $((Get-Date).ToString())"
  50. "-"*80 | Write-Host
  51. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  52. "Total number of account's initiated : " + $rowCount | Out-File -Encoding Ascii -append $outputfilepath
  53. "Started at :" + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
  54. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  55. ## Get Page Number Count
  56. $count = 1;
  57. for ($i=2; $i -le $rows; $i++)
  58. {
  59. try{
  60. #Get PageUrl column values. Eg : madhukumargk@<tenant>.onmicrosoft.com (online login account)
  61. $accountID = $sheet.Cells.Item($i, $pageurlcolumns).text
  62. #Get membership id for account id.
  63. $accountName = "i:0#.f|membership|" + $accountID
  64. #Log Account ID
  65. Write-Host -ForegroundColor Green "$count : " $accountID
  66. "$count : " + $accountID | Out-File -Encoding Ascii -append $outputfilepath
  67. ##Get quick links for the specified user account.
  68. $userLinks = $userProfileServiceWebServiceReference.GetUserLinks($accountName)
  69. ##Iterate on the comments collection and store the value in PageNoteBoardComments array collection.
  70. foreach($item in $userLinks)
  71. {
  72. $QuickLinksArray += New-Object PsObject -property @{
  73. 'URL' = [string]$item.Url
  74. 'Name' = [string]$item.Name
  75. 'Privacy' = [string]$item.Privacy
  76. 'Group' = [string]$item.Group
  77. 'ID' = $item.ID
  78. }
  79. }
  80. $count++
  81. }
  82. catch{
  83. Write-Host -ForegroundColor Green "$accountID : " $_.Exception.Message
  84. "$accountID : " + $_.Exception.Message | Out-File -Encoding Ascii -append $outputfilepath
  85. }
  86. }
  87. #Finally, use Export-Csv to export the data to a csv file
  88. $QuickLinksArray | Export-Csv -NoTypeInformation -Path $CSVOutputfilepath
  89. "-"*80 | Write-Host
  90. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  91. Write-Host -ForegroundColor Green "Completed at : $((Get-Date).ToString())"
  92. "Completed at : " + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
  93. Write-Host -ForegroundColor Green "Total QuickLinks Found : " $QuickLinksArray.Count
  94. "Total QuickLinks Found : " + $QuickLinksArray.Count | Out-File -Encoding Ascii -append $outputfilepath
  95. "-"*80 | Write-Host
  96. "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
  97. #Close the workbook object
  98. $WorkBook.close()
  99. #close the excel object
  100. $objexcel.quit()
Please feel free to share your comments.
I hope this helps!!!!!