Reorder UserProfile Properties

Reading Time: 3 minutes

I stumbled across some useful PowerShell cmdlets while trying to reorder SharePoint User Profile properties on the EditProfile page. Although these cmdlets have been around for a long time, I’ve never had the need to use them until just last week.

NOTE: I’ve tested these commands on SharePoint 2010 and 2013

If you’ve ever tried to use the SharePoint UI to reorder these properties you know it can be a slow and painful process.  Although it seems faster in SharePoint 2013 than it was in SharePoint 2010, I wanted to accomplish this task with PowerShell so I could quickly do it across farms.

If you don’t know what I’m referring to it’s the ‘Change Order’ column on the ‘Manage User Properties’ page of the UserProfile Service Application in Central Admin:

ChangeOrderUI

If you’re only moving a few properties up or down a couple of spots you will likely choose to do that thru the Central Admin UI.  However, I had a requirement to move 3 properties each up about 20 spots in 3 separate farms.  In one SharePoint farm I support we allow the end-user to update 4 phone numbers (Work, Mobile, Home, Fax) and push those values back to Active Directory.  We wanted these 4 fields to be together on the EditProfile.aspx page to make it convenient for end-users to update. Using the Central Admin UI was not a good option for this so I set out to accomplish this with PowerShell.


First thing to do is determine the order number you want your properties to end up with. Easy way to do this is to display the current order for the User Profile Subtype you’re wanting to modify.

Get an instance of the UserProfile  configuration manager for your MySite host, instantiate the user profile subtype you’re working with ProfileSubtypePropertyManager class – in my case the Default User Profile Subtype) and list the current order of its properties…

[code language=”powershell” light=”true”]
$MySite = Get-SPSite http://mysite
$Context = Get-SPServiceContext $MySite
$profileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($Context)
$defaultUserProfileSubType = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName("User")
$profileSubtypePropManager = $profileConfigManager.ProfilePropertyManager.GetProfileSubTypeProperties($defaultUserProfileSubType)

$profileSubtypePropManager | ft name, displayorder
[/code]

AllPropsOrder

 

Based on the above information, we can now create an XML configuration file to contain all User Profile property names you want to reorder and their new display order.

XML file example:

[code language=”xml”]
<Configuration>
<UPProperties>
<Property Name="Fax" DisplayOrder="12" />
<Property Name="CellPhone" DisplayOrder="13" />
<Property Name="HomePhone" DisplayOrder="14" />
</UPProperties>
</Configuration>
[/code]

Finally, run this script to iterate thru the configuration file using the Profile Subtype property manager and setting each property’s displayorder:

[code language=”powershell” highlight=”8,9,10,11,12,13″]
$mysite = Get-SPSite http://mysite
$context = Get-SPServiceContext $mysite
$upcManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context)

$defaultUserProfileSubTypeName = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName("User")
$profileSubtypePropManager = $upcManager.ProfilePropertyManager.GetProfileSubtypeProperties($defaultUserProfileSubTypeName)

$configFile = [xml](Get-Content "c:\xmlfilefromabove.xml")
foreach($prop in $configFile.Configuration.UPProperties.childnodes){
Write-Host "Updating Profile property" $prop.name "to position" $prop.DisplayOrder
$profileSubtypePropManager.SetDisplayOrderByPropertyName($prop.Name,$prop.DisplayOrder)
}
$profileSubtypePropManager.CommitDisplayOrder()
[/code]

BulkUpdateScript

You can now run this script across all environments … boom you’re done!

**From my testing, multiple properties can have the same display order; they will display on the EditProfile page in the order they appear in this list.

UserPropListAfterChange


THE END

It’s a simple script, but a timesaver if you find yourself needing to reorder numerous properties more than a few positions up or down.

Thanks for reading.

2 comments

    1. Hi Deepak,
      From my testing, multiple properties can have the same display order; they will display on the EditProfile page in the order they appear in the User Profile Property sub type order list (via PowerShell). No problem.

      Joanne K

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.