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".
Note
All the account names are under "Title" column in the Excel sheet.
Code Usage
All the account names are under "Title" column in the Excel sheet.
Code Usage
- #Path to the CSV output path file.
- $CSVOutputfilepath = "D:\Madhu\GetMyLinks.csv"
- #Path to the log file.
- $outputfilepath = "D:\Madhu\GetMyLinksLogs.txt"
- #Excel File path.
- $FilePath = "D:\Madhu\userlist.xls"
- #Create an empty System.Array object
- $QuickLinksArray = @()
- # Create an Object Excel.Application using Com interface
- $objExcel = New-Object -ComObject Excel.Application
- # Disable the 'visible' property so the document won't open in excel
- $objExcel.Visible = $False
- # Open the Excel file and save it in $WorkBook
- $WorkBook = $objExcel.Workbooks.Open($FilePath)
- # Load First sheet
- $sheet = $WorkBook.Worksheets.Item(1)
- #Find PageUrl and get the column position
- $pageurlcolumns = $sheet.UsedRange.Columns.Find('Title').Column
- #Get all the Rows within Excel
- $rows = $sheet.UsedRange.Rows.Count
- ## Get number of user in excel
- $rowCount = $rows - 1
- ## tenant admin url
- $siteUrl = "https://<tenant>-admin.sharepoint.com"
- ## Read sharepoint online loginname
- $loginname = "username@<tenant>.onmicrosoft.com"
- ## Read password
- $pwd = "XXXXXXX"
- ## Convert password to secure string.
- $securePassword = ConvertTo-SecureString $pwd –AsPlainText -Force
- ## Connect to sharepoint online
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $securePassword)
- ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
- $uri= $siteUrl + "/_vti_bin/UserProfileService.asmx"
- ## Disable default credentials
- $userProfileServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential False
- ## Load online credentials to user profile service.
- $userProfileServiceWebServiceReference.Credentials = $credentials
- ## Load Uri object
- $uriS = New-Object System.Uri($siteUrl)
- ## Initiate Cookie container object
- $container = New-Object System.Net.CookieContainer
- ## Auntenticate and set cookie.
- $container.SetCookies($uriS, $credentials.GetAuthenticationCookie($siteUrl))
- ## Load cookie container to user profile.
- $userProfileServiceWebServiceReference.CookieContainer = $container
- "-"*80 | Write-Host
- Write-Host -ForegroundColor Green "Total number of account's initiated : " $rowCount
- Write-Host -ForegroundColor Green "Started at : $((Get-Date).ToString())"
- "-"*80 | Write-Host
- "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
- "Total number of account's initiated : " + $rowCount | Out-File -Encoding Ascii -append $outputfilepath
- "Started at :" + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
- "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
- ## Get Page Number Count
- $count = 1;
- for ($i=2; $i -le $rows; $i++)
- {
- try{
- #Get PageUrl column values. Eg : madhukumargk@<tenant>.onmicrosoft.com (online login account)
- $accountID = $sheet.Cells.Item($i, $pageurlcolumns).text
- #Get membership id for account id.
- $accountName = "i:0#.f|membership|" + $accountID
- #Log Account ID
- Write-Host -ForegroundColor Green "$count : " $accountID
- "$count : " + $accountID | Out-File -Encoding Ascii -append $outputfilepath
- ##Get quick links for the specified user account.
- $userLinks = $userProfileServiceWebServiceReference.GetUserLinks($accountName)
- ##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
- }
- }
- $count++
- }
- catch{
- Write-Host -ForegroundColor Green "$accountID : " $_.Exception.Message
- "$accountID : " + $_.Exception.Message | Out-File -Encoding Ascii -append $outputfilepath
- }
- }
- #Finally, use Export-Csv to export the data to a csv file
- $QuickLinksArray | Export-Csv -NoTypeInformation -Path $CSVOutputfilepath
- "-"*80 | Write-Host
- "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
- Write-Host -ForegroundColor Green "Completed at : $((Get-Date).ToString())"
- "Completed at : " + $((Get-Date).ToString()) | Out-File -Encoding Ascii -append $outputfilepath
- Write-Host -ForegroundColor Green "Total QuickLinks Found : " $QuickLinksArray.Count
- "Total QuickLinks Found : " + $QuickLinksArray.Count | Out-File -Encoding Ascii -append $outputfilepath
- "-"*80 | Write-Host
- "-"*80 | Out-File -Encoding Ascii -append $outputfilepath
- #Close the workbook object
- $WorkBook.close()
- #close the excel object
- $objexcel.quit()
Please feel free to share your comments.
I hope this helps!!!!!

Join the conversation! Your thoughts help the community grow.