Using new-mailcontact to create contacts causes duplicates even if a user exists with same alias
I am trying to use the following to create contacts: $ImportFile = Import-Csv "c:\bat\ftemployees1.txt" ForEach ($user in $importfile){ $theuser = $user.User $thelast = $user.Last $thefirst = $user.First $thedisp = $user.DispName $theemail = $user.User + "@a.b.edu" New-MailContact -name $theuser -externalemailaddress $theemail -PrimarySmtpAddress $theemail -FirstName $thefirst -LastName $thelast -OrganizationalUnit a.b.c/Employees -DisplayName $thedisp } I only want it to create a contact if I dont already have the user or contact in active directory. The alias is same across contacts and employees. If there is a contact it doesn't create a duplicate but is will duplicate a user and create a contact. Our contacts are on another email system and have different email adresses then users which is probably why it creates the contact. Is there a way to get it to search the activedirectory for the alias and then not create the contact(or something like that)?? Thanks Steve
July 15th, 2011 10:01am

a simple check if AD already contains a recipient would do it. $ImportFile = Import-Csv "c:\bat\ftemployees1.txt" ForEach ($user in $importfile) { if (Get-Recipient $User) { write-host $user "found in AD" } else { # create a contact $theuser = $user.User $thelast = $user.Last $thefirst = $user.First $thedisp = $user.DispName $theemail = $user.User + "@a.b.edu" New-MailContact -name $theuser -externalemailaddress $theemail -PrimarySmtpAddress $theemail -FirstName $thefirst -LastName $thelast -OrganizationalUnit a.b.c/Employees -DisplayName $thedisp } } lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2011 10:47am

Hi steve, Lasse’s suggestion is good. I tested in my lab: $ImportFile = Import-Csv "C:\1.csv" ForEach ($user in $importfile){ if (Get-Recipient $user.User) { write-host $user "found in AD" } else { $theuser = $user.User $thelast = $user.Last $thefirst = $user.First $thedisp = $user.DispName $theemail = $user.User + "@a.b.edu" New-MailContact -name $theuser -externalemailaddress $theemail -PrimarySmtpAddress $theemail -FirstName $thefirst -LastName $thelast -OrganizationalUnit a.b.c/Employees -DisplayName $thedisp } } It will only create contacts for users who is not be found in AD. Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com
July 18th, 2011 2:34am

Thanks, On my own I came up with: if ((get-mailbox -Identity $_.User) -or (get-mailcontact -Identity $_.User) -or (get-mailuser -Identity $_.User)) but get-recipient seems to check them all. We were using old AD scripts to create the contacts, but they seem to have stopped working reliably with the upgrades to exchange. Thanks Again. Steve
Free Windows Admin Tool Kit Click here and download it now
July 18th, 2011 1:37pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics