Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Using PowerShell, I want to add properties to the user profile in 2013 and map those properties to be synchronized with Active Directory.

I can create the properties fine as well as the synchronization connection with Active Directory. To create the mapping between a user profile property and active directory in SP 2010 you would write something like this script:

$profileApp = @(Get-SPServiceApplication | `
    ? {$_.TypeName -eq "User Profile Service Application"})[0]
$serviceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext( `
    $profileApp.ServiceApplicationProxyGroup, `
    [Microsoft.SharePoint.SPSiteSubscriptionIdentifier]::Default)

$userProfileConfigManager = New-Object ` 
    Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)

$connection = $userProfileConfigManager.ConnectionManager["My AD Import Connection"]
$connection.PropertyMapping.AddNewMapping( `
    [Microsoft.Office.Server.UserProfiles.ProfileType]::User, `
    "MyPropName", `
    "My Data Source Property Name")

Running this in 2013 we receive the following error:

You cannot call a method on a null-valued expression.
At C:\Projects\...
+   $connection.PropertyMapping.AddNewMapping([Microsoft.Office.Server.U ...

The documentation for Connection.PropertyMapping for SP 2013 notes that PropertyMapping "Returns null if the connection type is ActiveDirectoryImport" http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.connection.propertymapping.aspx

The 2010 version of that API doesn't seem to have this restriction: http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.connection.propertymapping(v=office.14).aspx

This means that we can't call .PropertyMapping.AddNewMapping if we are intending to sync the user profile with AD.

Is there some new way to add mappings through PowerShell in 2013?

UPDATE:

The issue seems to be that when using the new 2013 'Active Directory Import' method of synchronization, the mappings between AD properties and user profile properties can't be configured using $connection.PropertyMapping

Question then is, how do we configure these mappings for Active Directory Import?

share|improve this question
1  
What kind of synchronization connection are you creating? SharePoint Profile Synchronization (UPS) or the new Active Directory Import? If you use Directory import, mapping of some properties are not possible (SPS prefixed properties). Also please supply us with code samples of what is not working. Creating Synchronization connections in code was not possible (or supported) in SP2010 and I haven't heard this has changed in SP2013, have you tried your mapping code on a synchronization connection created using the UI -just to determine if this is a factor? –  Anders Rask Aug 23 '13 at 7:44
    
I've previously created a synchronization connection of type Active Directory Import using the UI - I'm not trying to create the connection, just create the property mappings. The code that's not working is: $connection.PropertyMapping - it returns $null –  Daniel Aug 23 '13 at 16:42
1  
It looks like to me that you're calling a method intended for the UPS method but you're using the Active Directory Import... Are you required to use the Active Directory Import method or can you sync profiles using the UPS (note the UPS method is the SP2010 method and can be used to sync AD)? –  shufler Aug 26 '13 at 18:38
    
Aha, yes, that seems to be the problem. I need to find out how to create the mappings when using the 'Active Directory Import' method. I've updated my question to clarify that's what I'm doing –  Daniel Aug 27 '13 at 21:19

1 Answer 1

If your connection is of type "ActiveDirectoryImport", the methods of the classic sync-connection won´t work, because Microsoft implemented it in a different way. This is also reflected at http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.connection.propertymapping.aspx where they state, that the Connection.PropertyMapping property is NULL in case of ActiveDirectoryImport.
The great thing about it is, that it got much simpler through the ActiveDirectoryImportConnection.AddPropertyMapping method.

Try this:

$site = New-Object Microsoft.SharePoint.SPSite <centraladmin-URL>
$context = [Microsoft.SharePoint.SPServiceContext]::GetContext($site)
$configManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager $context
$UPAConnMgr = $configManager.ConnectionManager
$Connection = ($UPAConnMgr | select -First 1)
if ($Connection.Type -eq "ActiveDirectoryImport"){
$Connection.AddPropertyMapping("streetAddress","SPS-Location")
$Connection.Update()
}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.