Quantcast
Channel: Radu Tut » SharePoint 2010
Viewing all articles
Browse latest Browse all 4

Change order of user profile properties in SharePoint 2013 with Powershell

0
0

Management of user profile properties in SharePoint CA user interface is easy and intuitive, but when it comes to changing the display order of user profile properties, this becomes a difficult and frustrating task (and it has been like this since 2007). Powershell scripting proves again very handy.

You can find several other blog posts on this topic, but all I have found use the obsolete SharePoint API (2007) to do this.

First of all we need a PS script to list the current order of user profile properties.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
Add-Type -Path "C:\program files\common files\microsoft shared\web server extensions\15\isapi\Microsoft.Office.Server.dll"

#input parameter should be my site url
function ListUPPDisplayOrder($siteUrl){
$mysite = Get-SPSite $siteUrl
$context = Get-SPServiceContext $mysite
$upcManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context)

#if you have several profile sub-types, you might want to change the following line and use the name of the desired profile sub-type
$defaultUserProfileSubTypeName = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName("User")
$upcManager.ProfilePropertyManager.GetProfileSubtypeProperties($defaultUserProfileSubTypeName) | Format-Table -Property Name,DisplayName,DisplayOrder
}
#SAMPLE USAGE
#ListUPPDisplayOrder http://spdevel.social.com

Next step would be to set up a configuration xml file, that lets us define what properties we want to change. The following config sample will change the display order of two user profile properties.

<Configuration>
 <Properties>
  <Property Name="SPS-MemberOf" Order="37" />
  <Property Name="Manager" Order="60" />
 </Properties>
</Configuration>

The final step, the PS script that makes the changes. The function for update requires two input parameters: a config file path, and the my site url.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
Add-Type -Path "C:\program files\common files\microsoft shared\web server extensions\15\isapi\Microsoft.Office.Server.dll"

function UPPReorder($configFile,$siteUrl){
 $config = [xml] (Get-Content $configFile)
 $mys = Get-SPSite $siteUrl
 $context = Get-SPServiceContext $mys
 $upcManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context)

 #if you have several profile sub-types, you might want to change the following line and use the name of the desired profile sub-type
 $defaultUserProfileSubTypeName = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName("User")
 $profileSubtypePropManager = $upcManager.ProfilePropertyManager.GetProfileSubtypeProperties($defaultUserProfileSubTypeName)

 foreach($property in $config.Configuration.Properties.childnodes){
 $propName = $property.Name
 Write-Host "Updating property $propName ..."
 $profileSubtypePropManager.SetDisplayOrderByPropertyName($property.Name,$property.Order)
 }
 $profileSubtypePropManager.CommitDisplayOrder()
 Write-Host "Finished."
}
#SAMPLE USAGE
#UPPReorder C:\Temp\Blog\config.userproperties.xml http://spdevel.portal.com

The script gets the ProfileSubtypePropertyManager of the default user profile sub type, iterates through all properties defined in the configuration file, updates the display order of these properties, and then commits the changes.

An important thing to remember is about the user who will run these scripts. If that user does not have permissions(Full Control) on the User Profile Service Application, then you will receiver an error.

New-Object : Exception calling ".ctor" with "1" argument(s):
"UserProfileApplicationNotAvailableException_Logging ::UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 034ef0df-e47c-41bd-93d5-7834dd6fa20b"
At line:8 char:15+
$upcManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigM ...

That’s it! User profile properties are now configured in the desired order. In a few minutes, these changes can also be seen in CA user interface.



Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images