I created this following script to import “My Links” items into the SharePoint User Profile. This might be useful for a various reason including extracting existing links from another User Profile database (see SQL query below).
The script uses a CSV file containing three columns – username, title and URL e.g.
DOMAIN\User1,Google, https://www.google.com
DOMAIN\User1,Intranet, https://intranet
DOMAIN\User2, Team, https://intranet/teamsite
If you need to extract data from an existing User Profile Database use the following query in SQL Management Studio. The schema is the same on SP2010 and SP2013.
Use SP_UserProfile_DB
select UP.NTname, UL.title, UL.url
from dbo.UserLinks UL, dbo.UserProfile_Full UP
where UL.RecordId = UP.RecordId
Save the output as a CSV file. You don’t need to include a header row.
Now to import the data into the User Profile Service, run the following script. You may need to run this as the Farm Account.
$site= Get-SPSite(“https://mysiteURL”)
$filepath = “c:\mylinks.csv”
$context = Get-SPServiceContext($site)
$ProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$header = “Username”,”Title”,”URL”
$file = import-csv $filepath -delimiter “,” -header $headerforeach($line in $file)
{
write-host “—-”
write-host $line.UserName
$User=$ProfileManager.GetUserProfile($line.Username)
$QuickLinkManager = $User.QuickLinks
$Title = $Line.Title
$URL = $Line.URL
$quickLinkManager.Create($Title,$URL,3,$null,1)
}
That’s it. Now you have a script that can import thousands of items in seconds.
Note: Microsoft do not support directly updating SharePoint databases with a SQL query.