Powershell Task of the Day – Bulk add to a distribution list

A follow on from the previous script, I had to then add some users to a distribution list. The following command was used:

get-user -organizationalUnit "domai.local/Company/State/OfficeLocation/Department/Team" | `
select UserPrincipalName | `
foreach { Add-DistributionGroupMember -identity "SA IP Agents" -member $_.UserPrincipalName }

Like the previous script, line 1 is getting users from he specified OU. In this operation, we really only need the User Principle Name. Line 3 iterates through the results, using the Add-DistributionGroupMember cmdlet to add the user.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.