Bulk add user to distribution group

%3CLINGO-SUB%20id%3D%22lingo-sub-66309%22%20slang%3D%22en-US%22%3EBulk%20add%20user%20to%20distribution%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-66309%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EBulk%20add%20users%20to%20Distribution%20Group%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20ask%20recently%20to%20simplify%20a%20task%20for%20support%20staff%20to%20bulk%20add%20users%20to%20a%20distribution%20group.%20So%20i%20created%20the%20following%20script%20to%20add%20user%20from%20csv.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20script%20will%20%3CSTRONG%3E'prompt'%3C%2FSTRONG%3E%20for%20%3CSTRONG%3E'Distribution%20Group'%3C%2FSTRONG%3E%20name%20and%20will%20add%20users%20accordingly.%3C%2FP%3E%3CP%3EI%20have%20also%20added%20the%20'WhatIf'%20option%20by%20default.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%23Created%20to%20simplify%20daily%20tasks%3CBR%20%2F%3E%23Web%3A%20http%3A%2F%2Fthatlazyadmin.com%3CBR%20%2F%3E%23Twitter%3A%20Shaun.Hardneck%3CBR%20%2F%3EAdd-PSSnapin%20Microsoft.Exchange.Management.PowerShell.SnapIn%3B%3CBR%20%2F%3E%24DGroup%20%3D%20Read-Host%20'Insert%20Distribution%20Group%20Name'%3CBR%20%2F%3EImport-Csv%20'C%3A%5CSoftlib%5CUsers.csv'%20%7C%3CBR%20%2F%3EForEach%7B%3CBR%20%2F%3Etry%20%7B%20%3CBR%20%2F%3EAdd-DistributionGroupMember%20-Identity%20%24DGroup%20-Member%20%24_.name%20-ErrorAction%20stop%20-WhatIf%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Ecatch%20%5Bsystem.exception%5D%3CBR%20%2F%3E%7B%3CBR%20%2F%3EWrite-Host%20%22%24_.name%22%20-ForegroundColor%20Red%20%3CBR%20%2F%3E%7D%3CBR%20%2F%3EFinally%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%7D%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%20someone%20out%20there%20in%20the%20wild%20wild%20net.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fthatlazyadmin.com%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%23ThatLazyAdmin%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20128px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F14014i74EFDFE252D2416B%2Fimage-dimensions%2F128x128%3Fv%3D1.0%22%20width%3D%22128%22%20height%3D%22128%22%20alt%3D%22thatlazyadmin.png%22%20title%3D%22thatlazyadmin.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-66309%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-376934%22%20slang%3D%22en-US%22%3ERe%3A%20Bulk%20add%20user%20to%20distribution%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-376934%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2226%22%20target%3D%22_blank%22%3E%40Vinod%20Poojary%3C%2FA%3E%26nbsp%3B%20Just%20add%20the%20emailaddress%20in%20text%20file%20and%20feed%20to%20below%20script%2C%20it%20has%20status%20bar%2C%20error%20reporting%20%26amp%3B%20some%20handy%20features%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2FAdd-Bulk-Users-to-6f3014b2%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2FAdd-Bulk-Users-to-6f3014b2%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-315228%22%20slang%3D%22en-US%22%3ERe%3A%20Bulk%20add%20user%20to%20distribution%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-315228%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20script%20works%20for%20me%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24Dgroup%20%3D%20Read-Host%20'Insert%20Distribution%20Group%20Name'%3CBR%20%2F%3EImport-Csv%20%22C%3A%5Cscripts%5CAddDistGroupMembers.csv%22%20%7C%3CBR%20%2F%3Eforeach%7BAdd-DistributionGroupMember%20-Identity%20%24DGroup%20-Member%20%24_.email%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20the%20.csv%20file%20has%20a%20header%20%22email%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-131400%22%20slang%3D%22en-US%22%3ERe%3A%20Bulk%20add%20user%20to%20distribution%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-131400%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F49143%22%20target%3D%22_blank%22%3E%40Shaun%20Hardneck%3C%2FA%3E%26nbsp%3Bwhat%20would%20be%20the%20header%20in%20CSV%20file%3F%20Just%20Name%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Bulk add users to Distribution Group

 

I was ask recently to simplify a task for support staff to bulk add users to a distribution group. So i created the following script to add user from csv.

 

The script will 'prompt' for 'Distribution Group' name and will add users accordingly.

I have also added the 'WhatIf' option by default.

 

 

#Created to simplify daily tasks
#Web: http://thatlazyadmin.com
#Twitter: Shaun.Hardneck
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
$DGroup = Read-Host 'Insert Distribution Group Name'
Import-Csv 'C:\Softlib\Users.csv' |
ForEach{
try {
Add-DistributionGroupMember -Identity $DGroup -Member $_.name -ErrorAction stop -WhatIf
}
catch [system.exception]
{
Write-Host "$_.name" -ForegroundColor Red
}
Finally
{
}}

 

Hope this helps someone out there in the wild wild net.

 

#ThatLazyAdmin

 thatlazyadmin.png

3 Replies
Highlighted

@Shaun Hardneck what would be the header in CSV file? Just Name?

Highlighted

This script works for me:

 

$Dgroup = Read-Host 'Insert Distribution Group Name'
Import-Csv "C:\scripts\AddDistGroupMembers.csv" |
foreach{Add-DistributionGroupMember -Identity $DGroup -Member $_.email}

 

 

And the .csv file has a header "email"

Highlighted

@Deleted  Just add the emailaddress in text file and feed to below script, it has status bar, error reporting & some handy features

 

https://gallery.technet.microsoft.com/Add-Bulk-Users-to-6f3014b2