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, `

$userProfileConfigManager = New-Object ` 

$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?


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?

  • 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? Commented Aug 23, 2013 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
    Commented Aug 23, 2013 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
    Commented Aug 26, 2013 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
    Commented Aug 27, 2013 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"){  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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