Have you ever had a test or lab AD/Exchange environment that you wanted to populate with many users and mailboxes filled with Gigabytes of data which were close to real-world (e-mails, attachments in various formats etc)? Or maybe you’re preparing the Exchange migration and wanted to test the speed of moving mailboxes between servers? Then read on…
This is how you can create one user from command line in AD:
NET USER Testmig1 MyPassword=Password1 /ADD /Domain /Y
If you want to enable a mailbox for that user:
Enable-Mailbox Testmig1 -Database MDB1-DB01
So to create 100 users, you could use:
1..100 | ForEach { NET USER “Testmig$_” MyPassword=Password1 /ADD /Domain /Y; Enable-Mailbox “Testmig$_” -Database MDB1-DB01 }
So it’s really easy to created hundreds of users. An alternative if you don’t want to use NET USER is to use New-Mailbox which also creates the user:
New-Mailbox -Name “Test Migration” -UserPrincipalName testmigration@domain.local
You might notice it will ask you for the password. There’s a variable called -Password for New-Mailbox but it doesn’t allow it in cleartext in the command so you have to start with:
$password = Read-Host “Enter Password” -AsSecureString
And then:
New-Mailbox -Name “Test Migration” -UserPrincipalName testmigration@domain.local -Password $password
That’s just the minimal stuff, if you want to supply some more values to make it look better in AD and maybe supply which database, OU etc:
New-Mailbox -Name “Test Migration” -UserPrincipalName testmigration@domain.local -Password $password -FirstName “Test” -LastName “Migration” -OrganizationalUnit “domain.local/Exchmig/Users” -Database MDB1-DB01
And again, if you want to create 100 of them:
1..100 | ForEach { New-Mailbox -Name “Testmig$_” -UserPrincipalName “Testmig$_@domain.local” -Password $password }
And with all attributes:
1..100 | ForEach { New-Mailbox -Name “Testmig$_” -UserPrincipalName “Testmig$_@domain.local” -Password $password -FirstName “Test” -LastName “Testmig$_” -OrganizationalUnit “domain.local/Exchmig/Users” -Database MDB1-DB01 }
So now you have 100 users with empty mailboxes you could play around with. Not really a “real world scenario” with 100 users with 1 MB mailboxes…
Below you will find instructions how to do mass import of PST files in bulk on hundreds of users and Gigabytes of data.
But where do you get those PST files easily? Sure, you could manually open a mailbox, add some e-mails and manually export to PST, but that would take a lot of time and still not real world scenario since you would also need to add attachments such as PDF, Word, Excel etc. One alternative could be to do an export of your production environment and import it but for security reasons you might not be allowed to do that or you simply don’t want to risk to stumble over something you weren’t supposed to see.
So what I did was to spend a lot of time creating template PST files in different sizes ranging from 4 MB to 2 GB. These contains ordinary e-mails and attachments in various sizes and formats. All attachments are filled with nonsense lorem ipsum words but still real world documents with pictures, diagrams in the following formats and sizes ranging from 25 kB to 6 MB each:
- GIF
- JPG
- Microsoft Access
- Microsoft Excel
- Microsoft Powerpoint
- Microsoft Project
- Microsoft Publisher
- Microsoft Visio
- Microsoft Word
- PNG
You will find the instructions below but for the PST files I ask you to donate a small sum via PayPal since I spent quite a lot of time producing these. I hope you will find them valuable and time saving in your next upcoming Exchange migration project, so I hope you find them worth $2.99.
Once paid, you will instantly receive two e-mails, one from PayPal and one from us with a download link. If you don’t receive this link, please check your junk folder, otherwise, or if you have any other problems to download, e-mail us at info[a]sysadminlab.net and we’ll help out as soon as possible.
Preparations
Download the PSTs to an UNC path (yes, you can’t import/export to local drives).
Make sure “Exchange Trusted Subsystem” group has read/write access to this UNC-path.
Create a new Universal, Security group, named for example: MailboxImportExport
Add your admin user to this group
We need to assign that group the role “Mailbox Import Export”
New-ManagementRoleAssignment -Name “Import Export Admins” -SecurityGroup “MailboxImportExport” -Role “Mailbox Import Export”
If you forget this part you will get an errormessage: The term ‘New-MailboxImportRequest’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Restart EMS.
Importing
Then create the 100 users as described above. Then we’ll be using New-MailboxImportRequest to import the PSTs into the mailboxes (where you can select any PST file you like).
1..100 | ForEach { New-MailboxImportRequest -Mailbox “Testmig$_” -FilePath \\SERVER\PST\2MB.pst }
During import, you will not see any progress bar. But you can use the following cmdlet to get current status of the import. It will take some time before it changes from Queued to InProgress:
Get-MailboxImportRequest
If you want to get details, use:
Get-MailboxImportRequestStatistics Testmig1\MailboxImport
And once Completed, you can remove a single item:
Remove-MailboxImportRequest -Identity Testmig1\MailboxImport
Or you can remove all Completed items:
Get-MailboxImportRequest -Status Completed | Remove-MailboxImportRequest
That’s it! Check below for some other useful commands.
Notes
You can use Get-MailboxStatistics to get info on your newly imported mailboxes. You need to get all mailboxes and pipe to it:
Get-Mailbox | Get-MailboxStatistics
Maybe you just want to see the name and the size (you can use fl instead of ft for list view):
Get-Mailbox | Get-MailboxStatistics | ft DisplayName,TotalItemSize
You might just want to get the new ones you created which started with testmig*:
Get-Mailbox | Get-MailboxStatistics | where {$_.DisplayName -like “testmig*”} | ft DisplayName,TotalItemSize
There are many other ways to compare values, check this out for all of them.
When you create the users and you get “The requested search root ‘domain.local/Exchmig/Testmig’ is not within the scope of this operation. Cannot perform searches outside the scope ‘domain.local’.”. This could be caused if you’re running in a multi-domain environemtn. Then the solution is to run:
Set-AdServerSettings -ViewEntireForest $True