Link to home
Start Free TrialLog in
Avatar of defecta
defectaFlag for Australia

asked on

Add existing external contacts to distribution list with PowerShell

hey guys,

I have an Exchange 2010 server that I have imported some external contacts into an OU in AD using PowerShell and now I want to add all contacts in that OU to a distribution list.

I cant seem to add external mail contacts to the distribution list using PowerShell, only domain users. I can do it using the AD management console but I want to script this process hence why I am trying to do it with PowerShell.

Because of the problems I have encountered, to simplify things I am trying to add just one contact to the DL before trying to add the whole OU again. I have tried using the Name, DistinguishedName, Identity and even WindowsEmailAddress after the -member switch but nothing works.

Here is the single command I have been issuing and here is the output.
Add-DistributionGroupMember "All Suppliers" -member "CN=Supplier,OU=All Suppliers,OU=Domain Users,DC=domain,DC=local"
Couldn't find object "domain.local/Domain Users/All Suppliers/Supplier". Please make sure that it was spelled correctly or 
specify a different object.
    + CategoryInfo          : NotSpecified: (0:Int32) [Add-DistributionGroupMember], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : F5A15BE2,Microsoft.Exchange.Management.RecipientTasks.AddDistributionGroupMember
    + PSComputerName        : mail.domain.local

Open in new window


Is there a different command that I cant find any documentation on to add contacts to a DL from PowerShell? I haven't been able to find one in all my googling.

Thanks in advance.
AC
ASKER CERTIFIED SOLUTION
Avatar of Jeremy Weisinger
Jeremy Weisinger

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of defecta

ASKER

Dsnegi_25dec I have seen that thread which I was using as the basis of my script. With the exception of importing contacts from a CSV first I have been following the same steps and it doesn't work. Perhaps for the reasons Jeremy was alluding to.

Jeremy, I am yet to do as you have suggested but before I do, can you explain why I can add the same contacts to the distribution list without mail enabling them using the GUI but not via the shell?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks JJ, exactly what I was going to say.

Defecta, for Exchange to utilize the contacts and send to them, they need to be mail enabled. So what you did in ADUC won't have any affect unless those objects are already mail enabled.
Avatar of defecta

ASKER

Thanks guys, i never did test sending email to the contacts until after I questioned what you said. Of course you were right.