Create Large Numbers of Test Mailboxes

If you’re setting up a lab environment to test with, then you will probably want to crate test users within the environment.

You can use the following commands, either at the Exchange Management Shell or as a script to create these users:

 

$FirstNames = Get-Content .\FirstName.txt

$LastNames = Get-Content .\LastName.txt

$UsersToCreate = 1000

$Password = ConvertTo-SecureString “pass@word1” -AsPlainText -Force

$OU = “lisajanedesigns.local/People”

$Departments = “Finance”,“IT”,“Marketing”,“Engineering”,“Sales”,“Human Resources”

$UPNSuffix = “lisajanedesigns.local”

foreach ($Department in $Departments)

{

    New-DistributionGroup -Name $Department -OrganizationalUnit $OU

}

for ($i=0; $i -lt $UsersToCreate; $i++)

{

    $FirstName = $FirstNames[(Get-Random -Minimum 0 -Maximum ($FirstNames.Count1))]

    $LastName = $LastNames[(Get-Random -Minimum 0 -Maximum ($LastNames.Count1))]

    $Username = $($Firstname).$($LastName)

    $DisplayName = $($Firstname) $($LastName)

    $Department = $Departments[(Get-Random -Minimum 0 -Maximum ($Departments.Count1))]

    New-Mailbox -Name $DisplayName -SamAccountName $Username -UserPrincipalName $($Username)@$($UPNSuffix) -Alias $Username  -OrganizationalUnit $OU -Password $Password -FirstName $FirstName -LastName $LastName

    Set-User -Identity $Username -Department $Department

    Add-DistributionGroupMember -Identity $Department -Member $Username

}

 

 In the above example, alter the following values to match your environment:

  • Change the number of $UsersToCreate to match the number of test users you need.
  • Change the $Password value to a suitable password to use with each test user.
  • Change the $OU value to an Organizational Unit within your lab’s Active Directory.
  • Change the list of $Departments to a suitable list of test departments you want the script to create distribution groups for and randomly assign test users to.
  • Finally change the $UPNSuffix value to a User Principal Name suffix suitable for your environment.

The script will then create a number of test distribution groups, and then create new users with mailboxes with randomly assigned names. Each user will have a department randomly assigned and be added to a distribution group.

If you’re looking for sample names to use with the script, you can download files that work with the above Powershell script from here. Extract those files to the same directory that you plan to execute the script from.

 

 

About The Author

1 thought on “Create Large Numbers of Test Mailboxes”

  1. Steve – Just FYI, the files in the Names.zip download are csv but your script is attempting to use .txt files. I had to change the script to reflect that but then it worked without a hitch. Huge time saver! Thanks.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top