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.
- 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
- ##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.
- #Path to the CSV output path file.
- $CSVOutputfilepath = "D:\XXXX\GetMyLinks.csv"
- #Path to the log file.
- $outputfilepath = "D:\XXXX\GetMyLinksLogs.txt"
- #Excel File path.
- $FilePath = "D:\XXXX\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 Page Number Count
- $count = 1;
- ## Get number of user in excel
- $rowCount = $rows - 1
- "-"*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
- for ($i=2; $i -le $rows; $i++)
- {
- try{
- #Get PageUrl column values - Eg: Domain\accountID
- $accountID = $sheet.Cells.Item($i, $pageurlcolumns).text
- #Log Account ID
- Write-Host -ForegroundColor Green "$count : " $accountID
- "$count : " + $accountID | Out-File -Encoding Ascii -append $outputfilepath
- ## Get path of user profile webservice file
- $uri = "http://<site>/_vti_bin/UserProfileService.asmx?wsdl"
- ## Web Service Reference - http://Site/_vti_bin/UserProfileService.asmx
- $userProfileServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
- ## Retrieve user links by account name
- $quickLinksOnAccountID = $userProfileServiceWebServiceReference.GetUserLinks($accountID)
- foreach($item in $quickLinksOnAccountID)
- {
- $QuickLinksArray += New-Object PsObject -property @{
- 'ID'= $item.ID
- 'Name' = [string]$item.Name
- 'URL' = [string]$item.Url
- 'Group' = [string]$item.Group
- 'Privacy' = [string]$item.Privacy
- 'UserLoginID' = [string]$accountID
- }
- ##Add comments for a specific page.
- #$WriteCommentsOnUrl = $socialDataServiceWebServiceReference.AddComment($url,$item.Comment,0,"TestMultiline")
- }
- $count++
- }
- catch{
- Write-Host -ForegroundColor Green "$count : $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.
Hope this helps !!!!

Join the conversation! Your thoughts help the community grow.