2

We are on Sitecore 8.1.3 and have a user profile where personal links are stored as a path unfortunately and when the page gets move (not too often) the personal link is broken.

For now we would like to run a powershell script to find and replace the path ("Common/menu" to "Shared/WestCafeteria")". I have a find/replace script for the content tree, but not sure the path of all the user information and if that process should be used.

Attached image may be helpful (I removed the path in the personal link area). enter image description here

Thanks in advance.

Personal Links data sample:

{"ID":"{66666CC6-C66C-66B3-6666-666A6D6AB666}","Title":"Cafeteria menus","TargetID":"{66666666-B666-4666-A666-6666666666B17}","TargetUrl":"/departments-services/support-services/nutritional-services/dining-locations","TargetWin":"_top"}

  • Can't quite make out the format you are using in the Personal Links field from the screenshot. It looks like json? Can you provide more details on the format? – Radical Dave Dec 6 '17 at 22:09
  • Added data sample – DanO Dec 6 '17 at 22:54
5

You can use the Get-User command in SPE to get a collection of users to process, and then these are retrieved as an enumeration of Sitecore.Security.Accounts.User, which gives you access to the custom profile.

This is a sample script which fill find all extranet users and update them, you can alter the configuration at the top of the script to change the find/replace values. It just uses a simple string replacement.

# Configuration
$profileFieldName = "PersonalLinks"
$searchFor = "Common/menu"
$replaceWith = "Shared/WestCafeteria"
$userFilter = "extranet\*"

# Script
$users = Get-User -Filter $userFilter

foreach ( $user in $users )
{
    Write-Host "Updating $($user.Name)"

    # Get the custom field value
    $links = $user.Profile.GetCustomProperty($profileFieldName)

    # Update the value
    $links = $links -replace $searchFor, $replaceWith

    # Save the value back into the user
    $user.Profile.SetCustomProperty($profileFieldName, $links)
}

Note that the Get-User command supports partial matching on name, and also a ResultPageSize property to limit the results, which you may want to bear in mind if the size of your user-base is large.

4

To get user information, you have to get the user (you can use Sitecore API or SPE cmldet) and read properties. My example user:

enter image description here

How to read it in SPE.

enter image description here

code:

$user = Get-User "sitecore\a"
$user.Profile.SerializedData

To update/save settings simply update the field/property

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.