howto://create test users with mailboxes and data



Today’s post came out of a need to create 500 test users in AD, provision mailboxes for those users in Exchange 2010, and populate the mailboxes with data, all of which will be used to test velocity migrations from the on-prem Exchange 2010 environment to Office 365. As such, this post gets five different tags, which may be a record for me. To accomplish this task, I need three distinct steps to pull it off. I expect that there is an easier way to do it, or to do some of the separate operations in combined steps, but this works for me, so here it is. If you need to create a few hundred users, give them mailboxes, and add data to those mailboxes, you know what to do next.

This post assumes you have at least Domain Admin and Exchange Org membership, and that your Exchange servers are running at least Exchange 2010 SP2. If they are not, stop, this won’t work for you. It also requires the Quest AD PowerShell snap-in. You can download it from this page and if you are using a 64 bit machine for the AD stuff, you can grab the MSI from ActiveRoles Management Shell for Active Directory 64-bit. In the script below, I am using as my domain, and TestUsers as the OU in that domain. You can adjust your values as necessary.

  1. On a workstation that is domain joined, or on a domain controller, download and install the Quest ActiveRoles Management Shell (link above.)
  2. Open an administrative PowerShell session (not an EMS or remote PS) and run the following command.
    Add-PSSnapin Quest.ActiveRoles.ADManagement [enter]
  3. Now create a PowerShell script to create the users. I borrowed heavily from Austin Osuide’s post at the site to create this one. You can use mine, or Austin’s, or roll your own to fit your needs.
    #Create the csv file with headings as shown below. You can add additional headings if you wish, just make sure you populate them and call them later in the script.

    $outfilename = "out.csv"

“samAccountName,userPrincipalName,cn,sn,givenName,displayName,Password” | Out-File $outfilename –

encoding ASCII
# Now, populate the csv for 500 users. Increase/decrease the 501 as needed for the number of users you want.
for ($i = 11; $i -lt 501; $i++){

$samAccountName = “testUser” + “$i”

$userPrincipalName = ‘testUser’ + “$i” + ‘’

$cn = “test”

$sn = ‘user’ + “$i”

$givenName = “test”

$displayName = “Test” + ” ” + “User” + “$i”

$password = “Password1”
“$samAccountName, $userPrincipalName, $cn, $sn, $givenName, $displayName, $password” | Out-File
$outfilename -encoding ASCII -append

# Import the csv entries into AD as user objects
Import-Csv out.csv | ForEach-Object { New-QADuser -ParentContainer
‘OU=TestUsers,DC=example,DC=com’ -Name $_.samAccountName -samAccountName $_.samAccountName –

userPrincipalName $_.userPrincipalName -FirstName $ -LastName $ -displayName $_.displayName
-password $_.password }
# Enable the user objects
Get-QADUser -SearchRoot ‘OU=TestUsers,DC=example,DC=com’ | Set-QADuser -ObjectAttributes @


  • In the same PowerShell session, run the script you just created. Expect it to show out of order numbers as it creates the users. I don’t know why.
  • Then on the Exchange server, open an Exchange Management Shell and run this command. It’s all one line. I got this from an answer Karl Mitschke submitted to a support forum question.Get-User -OrganizationalUnit "OU=TestUsers,DC=example,DC=com" -Filter 'RecipientType -eq "user"' | ForEach-Object { $email = $_.FirstName +"."+ $_.LastName +""; Enable-Mailbox -Identity $_.SamAccountName -DisplayName $_.DisplayName -Alias $_.SamAccountName -PrimarySmtpAddress $email -Database "Mailbox Database 0500606304"} [enter]

    Note, you can omit the –Database “string” if you want to let Exchange create the mailboxes across all available databases.

  • Now, before you can begin the final stage, you must grant your account permissions to Import and Export mailboxes. If you don’t do this, you won’t even see the command we need later. In the same EMS session, run this command for your user account.

    New-ManagementRoleAssignment –Role “Mailbox Import Export” –User AD\efisher [enter]

  • Log off and back on.
  • Create a share on the Exchange server (or elsewhere) to store your PST file for import. For the import to work, the PST must be accessed using a UNC path, even if you store it on the Exchange server. We’ll assume you have it on \\FS1\PST
  • Grant the Exchange Trusted Subsystem Full Control to the Share, and also NTFS permissions.
  • Now run this command to import the PST to all your test users. Depending on the size of the PST and number of users, expect this to take hours.

    get-mailbox –organizationalunit TestUsers | new-mailboximportrequest –filepath \\FS1\PST\data.pst [enter]


And you’re done! Well, you are done. The EMS will need time to churn through all the imports. You can run this command to see how things are progressing.

get-mailboximportrequest | ft mailbox, targetdatabase, status –auto [enter]

Keep an eye on things, and sooner or later, you will have all the test mailboxes you need.

I started my morning looking for a one-stop solution that would do all this for me. I did not find that. But I did find enough pieces and parts across a handfull of posts and forums to cobble this all together, and that is just what I needed. I love the Internet. If you search hard enough, and well enough, there’s always someone out there who will give you just enough to send you on your way.

Direct link for RSS and email subscribers…

If this post helped you out at all, how about a shout out with a comment below, or maybe even a follow on Twitter? It’s costs nothing, and shows the love. Retweets are nice too!