SharePoint – AD Import: Using PowerShell to create property mappings

First off, when using Active Directory Import in SharePoint 2013, 2016, and 2019, it’s completely normal to see very few (like 2) mapped properties in the User Profile Service Application (UPA) | Manage User Properties. That’s because with AD Import, those property mappings are hard-coded and not shown on that page. See my other post here for details on that.

But let’s say you want to want to add or change a property mapping, and you’d like to do it via PowerShell to ensure consistency. Here’s an example of how you’d do that:

I have two AD Import connections, and in both cases, the WorkEmail property is mapped to “proxyAddresses”:

But in my “Contoso” domain users have no value for “proxyAddresses”. Instead, I want to use the “mail” AD attribute. I run the following PowerShell script to change the mapping to “mail”, but in this example, I only want to change it for the “contoso” AD Import connection.

### Set some variables ###
$URL = "http://teams.contoso.com/" #Any site associated with the UPA
$spsProperty = "WorkEmail"   #The internal name of the user profile property you want to map
$adAttribute = "mail"   #The name of the Active Directory attribute to map to $spsProperty
$ConnnectionName = "contoso"   #The display name for the AD Import connection to update
### Change nothing below this line ### 
Add-PSSnapin microsoft.sharepoint.powershell
$site = get-spsite $url
$context = [Microsoft.SharePoint.SPServiceContext]::GetContext($site)
$configManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager $context
$UPAConnMgr = $configManager.ConnectionManager
$Connection = $UPAConnMgr[$ConnnectionName]
$Connection.AddPropertyMapping($adAttribute,$spsProperty)
$Connection.Update()

As you can see, the mapping is properly updated.

If you wanted to make the same mapping for all AD Import connections, you would just do a ForEach for the connections instead of specifying one by name. Ex:

foreach($Connection in $UPAConnMgr)
{$Connection.AddPropertyMapping($adAttribute,$spsProperty)
$Connection.Update()}

And if you’re wondering where to find this “internal name” that you have to specify for $spsProperty, it’s shown at the top of the page when you edit a property:

Add a Comment