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!”}
else
{Write-Host “Failed to obtain site reference”}
$serviceContext = Get-SPServiceContext($site)
if ($serviceContext)
{Write-Host “Successfully obtained service context!”}
else
{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!”}
else
{Write-Host “Failed to obtain user profile manager”}
$synchConnection = $upManager.ConnectionManager[$connectionName]
if ($synchConnection)
{Write-Host “Successfully obtained synchronization connection!”}
else
{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]"
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.
ReplyDelete