A short but useful post:
Suppose you need to import hundreds of members to a distribution group.
The list is in a CSV file:
Name,Email
user1,user1@domain1.com
user2,user2@domain2.com
user3,user3@domain3.com
user4,user4@domain4.com
user5,user5@domain5.com
user6,user6@domain6.com
user7,user7@domain7.com
user8,user8@domain8.com
user9,user9@domain9.com
user10,user10@domain10.com
user11,user11@domain11.com
user12,user12@domain12.com
user13,user13@domain13.com
user14,user14@domain14.com
user15,user15@domain15.com
user16,user16@domain16.com
user17,user17@domain17.com
user18,user18@domain18.com
...
To bulk import all the users, a simple command like this is enough:
Import-Csv "" | foreach { Add-DistributionGroupMember "" -Member $_.Email }
For example:
Import-Csv "D:\Files\UsersToImport.csv" | foreach { Add-DistributionGroupMember "MyGroup" -Member $_.Email }
In case your fields are delimited with another character (instead of comma like the example), dont forget to use the “-delimiter” parameter.
For example:
Name;Email
user1;user1@domain1.com
user2;user2@domain2.com
user3;user3@domain3.com
user4;user4@domain4.com
user5;user5@domain5.com
...
Import-Csv "D:\Files\UsersToImport.csv" -Delimiter ";" | foreach { Add-DistributionGroupMember "MyGroup" -Member $_.Email }
If the field name contains special characters, use {} for the field.
Name;E-mail
user1;user1@domain1.com
user2;user2@domain2.com
user3;user3@domain3.com
user4;user4@domain4.com
user5;user5@domain5.com
...
Import-Csv "D:\Files\UsersToImport.csv" -Delimiter ";" | foreach { Add-DistributionGroupMember "MyGroup" -Member $_.{E-mail} }