Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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
}
share|improve this answer
    
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 '12 at 13:04
    
Added more code for the import –  uSlackr Mar 30 '12 at 13:30
    
This did what I needed, thank you. –  TheCleaner Apr 17 '12 at 14:17
add comment

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)"} }

Keep in mind though that I'm fairly new to PowerShell myself, so I may have made a mistake. I did test it on a single user, but not on a large scale.

share|improve this answer
    
Thanks, I commented on uSlackr's answer for both. –  TheCleaner Mar 30 '12 at 13:03
add comment

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.