Monday, September 14, 2015

SharePoint - Map Missing AD Attribute to User Profile Property

There are a few Active Directory Attributes that are not listed on the "Add User Profile Property" page. To add a missing attribute you have to first add a user profile property that uses any attribute from the attribute list and then modify the entry using the SharePoint Management Shell. You need to run the Management Shell with a user account that will have right permissions or you will run into errors.
The following is an example of the script:

# Richrd Golebiowski
# January 12, 2012
# Run in Sharepoint Managemnt Shell as SP_Farm
$url = "http://myssp:1000" #URL of your Central Admin site.
$spsProperty = "PostOfficeBox” #Internal name of the SharePoint user profile property
$fimProperty = "postOfficeBox” #Name of the attribute in FIM/LDAP source
$connectionName = “Ad Primary Connection” #Name of the SharePoint synchronization connection

$site = Get-SPSite $url

if ($site)
{Write-Host “Successfully obtained site reference!”}
{Write-Host “Failed to obtain site reference”}

$serviceContext = Get-SPServiceContext($site)

if ($serviceContext)
{Write-Host “Successfully obtained service context!”}
{Write-Host “Failed to obtain service context”}
$upManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)

if ($upManager)
{Write-Host “Successfully obtained user profile manager!”}
{Write-Host “Failed to obtain user profile manager”}
$synchConnection = $upManager.ConnectionManager[$connectionName]

if ($synchConnection)
{Write-Host “Successfully obtained synchronization connection!”}
{Write-Host “Failed to obtain user synchronization connection!”}

Write-Host “Adding the attribute mapping…”
$synchConnection.PropertyMapping.AddNewMapping([Microsoft.Office.Server.UserProfiles.ProfileType]::User, $spsProperty, $fimProperty)
Write-Host “Done!”

I tried running the script with my personal admin account instead of the farm account and ran into a lot of errors. The most interesting was executing "new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)" would set "$upManager" and then show "Successfully obtained user profile manager!" but the ConnectionManager would be empty and I would get a "Cannot index into a null array." error when executing "$synchConnection = $upManager.ConnectionManager[$connectionName]"

1 comment:

  1. Thank you very much! I was trying to use a modified version of this script and kept getting "Cannot index into a null array". My problem was the same as you: with the farm account it worked fine.


Thank you for commenting!