Bulk adding contacts to a Distribution List.
Import-CSV C:\FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name} Im trying to use the following script to bulk add mail enabled contacts to multiple DLs (1 DL at a time). My question is, is there a way to add some code that will capture any errors (especially users that could not be added to the intended DL) to a text file? Thank you in advance for your help.TD
September 21st, 2011 10:37pm

I would probably just start out with using -whatif -verbose and piple out to txt file >c:\errors.txt and just manually filter using excel. As far as capturing errors for a simple cmdlet task like this it's going to be something along the lines of name in the csv file is not matching the account or something of that nature which the cmdlet will tell you anyways.James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
September 21st, 2011 10:59pm

Im really a novice when it comes to scripting. So with that being stated, how would I write the full command to accomplish what I am trying to accomplish? Thank you.TD
September 21st, 2011 11:02pm

You can do below, the whatif just similuates the command without making changes. The verbose shows more detail when excuting the command. Import-CSV C:\FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name} -whatif -verbose To send to txt file. Import-CSV C:\FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name} -whatif -verbose >c:\report.txtJames Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
September 21st, 2011 11:10pm

Thanks. I will give it go and let you know what happens.TD
September 21st, 2011 11:14pm

Iam getting the following error when I runthe command above: "ForEach-object : cannot bind parameter 'Process' . Cannot convert the "whatif" value of type "System.String" to type "System.Management.Automation.ScriptBlock". At line:1 char:36 + Import-CSV C:\FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name} -whatif -verbose >c:\report.txt + CategoryInfo : InvalidArgument: <:> [ForEach-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage, Microsoft.PowerShell.Commands.ForEachObjectCommand TD
Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2011 12:12am

Sorry end is wrong. Import-CSV C:\user.txt | ForEach {Add-DistributionGroupMember -Identity "DL" -Member $_.Name -whatif -verbose} However it appears you can't pipe out the results thoug. James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
September 22nd, 2011 2:06am

I have tried that the corrected version, but it looks like when I run it, the script is still additional input/commands. Thanks for the help though. Will see if someone can suggest something different.TD
Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2011 3:46am

It works fine for me, output below. [PS] C:\>Import-CSV C:\user.txt | ForEach {Add-DistributionGroupMember -Identity "server_Eng" -Member $_.Name -whatif -verbose} VERBOSE: Add-DistributionGroupMember : Beginning processing. VERBOSE: Add-DistributionGroupMember : Searching objects "server_Eng" of type "ADGroup" under the root "$null". VERBOSE: Add-DistributionGroupMember : Previous operation run on domain controller 'DCFCDC03.ipcfcdom.inphonic.com'. VERBOSE: Add-DistributionGroupMember : Processing object "ipcfcdom.inphonic.com/Distribution Groups/server_eng". VERBOSE: Add-DistributionGroupMember : Searching objects "jmigration" of type "ADRecipient" under the root "$null". VERBOSE: Add-DistributionGroupMember : Previous operation run on global catalog server 'DCEXDC03.ipcexdom.inphonic.com'. What if: Adding Distribution Group Member "jmigration" on Distribution Group "se rver_Eng". VERBOSE: Add-DistributionGroupMember : Ending processing. [PS] C:\> James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
September 22nd, 2011 3:49am

I am saying the part that is not working is the part to write any errors to an output file.TD
Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2011 3:52am

Ahh yes that's what I mentioned, seems like it's not supported for this cmdlet. I tried, >,output file,export.csv none seem to work.James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
September 22nd, 2011 4:43am

What fields need to be present in the csv file when creating it to bulk add contacts to a distribution list
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2012 2:18pm

The fields you need any one of these. GUID distinguished name UPN LegacyExchangeDN Domain\Account Name SMTP AddressJames Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
April 13th, 2012 2:31pm

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

Other recent topics Other recent topics