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.

Powershell Task of the Day – Bulk Email Account Creation

A new office requires a large number of email accounts to be created. Fortunately, the users already had Active Directory accounts and they were in the same organisational unit. I used the following Powershell command to create the users:

get-user -OrganizationalUnit "domain.local/Company/State/OfficeLocation/Department/Team" | `
where-object {$_.RecipientType -eq "User"} | `
Enable-Mailbox -database "EXCH01StorageGroup1Database1"

Line 1 gets the users in the specified organisation unit, while line 2 narrows the results to just User objects. Line 3 performs the actual mailbox creation. 86 users were created with effectively one line of code.

Bitnami