2

I have domain accounts that I have created as contacts in another trusted domain so that they can see them in their Exchange GAL.

I need a way to extract the phone number field from UserA (user account) in DomainA and import it into UserA (contact) in DomainB.

I get the logic, it's just the code (vbscript/powershell/whatever) that eludes me.

The logic as I see it:

  1. Connect to source AD (ou/subtree)
  2. Extract user accounts from OU and subcontainers including first name, last name, display name, and phone number
  3. Connect to target AD (ou/subtree)
  4. Verify/match contact with extract in #2 above based on display name
  5. Update phone field with phone number in extract
  6. Write log of success and failures

Anybody able to help?

2 Answers 2

4

The problem is how do you match the account on one side with the account on the other. This will do the extract.

Any ideas on how to do the match on the import? Do you have a common field like employeeID in both? Otherwise a complicated multi-field matching might be needed.

   get-aduser -filter * -searchbase "ou=users,dc=adomain,dc=com" -properties Telephonenumber|select displayname, givenname, sn, telephonenumber|export-csv phones.csv

import-csv phones.csv| foreach { 
  get-aduser -displayname $_.displayname -searchbase "ou=contacts dc=Bdomain,dc=com"  | set-aduser -telephoneNumber $_.telephonenumber
}
2
  • The display name will be the same for 99% of them, so I can key off display name like Justus says below. I'll test out a hybrid of the two scripts. Thanks guys.
    – TheCleaner
    Mar 30, 2012 at 13:04
  • Added more code for the import
    – uSlackr
    Mar 30, 2012 at 13:30
2

As long as all of your DisplayNames in Domain A truly do match your DisplayNames in Domain B, the following should do the trick.

In Domain A, run:

Get-ADUser -filter * -properties TelephoneNumber,DisplayName | select DisplayName,TelephoneNumber | export-csv users.csv

In Domain B, run:

Import-CSV users.csv | ForEach { get-aduser -filter "displayname -eq '$($_.displayname)'" | set-aduser -replace @{telephonenumber="$($_.TelephoneNumber)"} }
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .