Search code examples
powershellexchange-server

how to sync an exchange attribute to on premise AD Object


I have a few users with custom attributes. I want to copy the value of these custom attributes and add them to the users ExtensionAttribute property in their AD object.

So far I have tried :

 $CustomAttr1 = get-mailbox  $upn | Select CustomAttribute1
 Set-ADUser -server Server -identity Identity -Add @{ExtensionAttribute1=$CustomAttr1}

The end result is just "@{$CustomAttribute1}" in the actual AD attribute.

How can I extract the string value of 'CustomAttribute1' from Exchange and pass it into AD?


Solution

  • The Select will filter the resulting object to a have a single property, CustomAttribute1. So when you need to set the value, you have to reference the property $CustomAttr1.CustomAttribute1 to get the value:

    $CustomAttr1 = get-mailbox  $upn | Select CustomAttribute1
    Set-ADUser -server Server -identity Identity -Add @{ExtensionAttribute1=$CustomAttr1.CustomAttribute1}