首先将以下脚本保存为PowerShell文件,如:ReorderUserProfileProperty.ps1。shell
在执行此脚本时,若是不输入任何参数,将列出全部用户配置文件属性的名称和显示次序;若是只输入属性名称,则显示此属性的显示次序;若是输入了属性名称和显示次序,则修改此属性的显示次序。app
#################################################################################### # Function: Re-order a user profile property, or show display order of a or all properties. # Return: If $PropertyName is null, the display order of all properties will be shown. # if $DisplayOrder is null, the display order of $PropertyName will be shown. # Otherwise, the display order of $PropertyName will be re-ordered. #################################################################################### param( [string]$PropertyName, [int]$DisplayOrder, [string]$SiteUrl ) [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles.UserProfileManager") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") if(!$SiteUrl) { $SiteUrl = 'http://SharePointServer:80/' } $site = new-object Microsoft.SharePoint.SPSite($SiteUrl); $context = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); if (!$context) { write-host "context is empty, quitting!" break } $UPAConfMgr = new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context) if (!$UPAConfMgr) { write-host "confmgr is empty, quitting!" break } $userprofiletype = [Microsoft.Office.Server.UserProfiles.ProfileType]::User $userProfileSubTypeManager = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::Get($context) $userProfile = $userProfileSubTypeManager.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName($userprofiletype)) $userProfileProperties = $userProfile.Properties if($PropertyName) { $sec = $userProfileProperties.GetPropertyByName($PropertyName) Write-Host 'Current Order: '$sec.DisplayOrder } else { $userProfileProperties | Format-Table -Property Name,DisplayOrder,DisplayName -AutoSize } if ($DisplayOrder) { $userProfileProperties.SetDisplayOrderByPropertyName($PropertyName,$DisplayOrder) Write-Host 'New Order: '$sec.DisplayOrder } $userProfileProperties.CommitDisplayOrder()
在使用此结果过程当中,可能会遇到以下问题,其解决办法以下:wordpress
1. 在执行脚本时提示以下错误:ui
New-Object : 使用“1”个参数调用“.ctor”时发生异常:“没有用户配置文件应用程序可用于处理请求。
【解决办法】:
办法一:在 管理中心 > 应用程序管理 > 管理服务应用程序 页面中,选中“User Profile Service Application”(但不要跳转),而后在Ribbon的“管理员”和“权限”中给当前用户赋予“Full Control”权限。
办法二:“以管理员身份运行”SharePoint 2010 Management Shell。spa
2. 管理用户属性页面显示异常code
有时,在执行完脚本后 管理中心 > 应用程序管理 > 管理服务应用程序 > User Profile Service Application > 管理用户属性 页面会提示属性信息错误。orm
【解决办法】:在页面中对任意属性手工排序,则页面显示将恢复正常。blog
3. 属性显示次序不会自动重排排序
在修改某一属性的显示次序时,其余相邻属性的次序不会自动重排。所以,在用此脚本单独修改属性后,可能会出现相同显示次序的属性,从而达不到指望的显示次序。get
【解决办法】:规划好各属性的显示次序后,按以下格式的脚本统一执行:
.\ReorderUserProfileProperty.ps1 MIS-StaffNo 11 .\ReorderUserProfileProperty.ps1 Department 12 .\ReorderUserProfileProperty.ps1 MIS-JobTitle 13 .\ReorderUserProfileProperty.ps1 SPS-JobTitle 14
参见:
http://www.sharepointstuffs.com/creating-managing-and-ordering-user-profile-properties-using-powershell-in-sharepoint-2013/
http://littletalk.wordpress.com/2010/12/09/no-user-profile-application-available-to-service-the-request/