Update Jan 2023: Feel free to use this Bulk-Create-AD-Users-Script (Just remeber to change the domain details in the “Global Variables’ Sections to give you 10o0 users, with sensible names addreeses etc.
Having a test network, is great for both learning, and testing. I’ve got some major migrations coming up in the next few months, so I’m in the process of running up some new test servers. I usually run a quick .vbs file like this;
[box]
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
For i = 1 To 1000
Set objLeaf = objContainer.Create("User", "cn=UserNo" & i)
objLeaf.Put "sAMAccountName", "UserNo" & i
objLeaf.SetInfo
Next
WScript.Echo "1000 Users created."
[/box]
Save that as createusers.vbs and run it on your domain controller and it will churn out 1000 users (named UserNo1 – UserNo1000). They will be disabled, with no passwords, but that can be rectified with a few mouse clicks.
But I want something a little more realistic, so I found a random name generator, and decided to have a script to create 1000 users that were a little more ‘lifelike’.
Solution
1. Download this zip file, and extract it to your desktop. To run the script you will need to set your Execution Policy with the following command;
[box]
Set-ExecutionPolicy Unrestricted[/box]
2. You will need to change a couple of lines in the newusers.ps1 file open it with notepad and change the domain details to match yours;
I had to do this a few weeks ago, so I documented it. I had a list of usernames in a CSV file and I needed to bulk-add them to a security group.
Bulk Add Group Users Solution
Firstly you will need the usernames (sAMAccountNames) in .csv format like so, (Note: As a header Im using User-Name.) I’ve saved the file to C:\Temp on my server.
Before SP1 you would have to install a copy of Outlook on the Exchange server and use a PowerShell command that looks like this (once you had granted Import/Export rights);
[box]
BEFORE Exchange 2010 SP1
Get-Mailbox | Import-Mailbox –PSTFolderPath C:Folder_Containing_PST_Files
[/box]
However try that after SP1 and you will get an error message, saying that Import-Mailbox is not a commandlet. That’s because now you no longer use this command you use “New-MailboxImportRequest”, and you also no longer need Outlook installing on the server.
“This mailbox exceeded the maximum number of large items that were specified for this request. (Fatal error TooManyLargeItemsPermanentException has occurred.)”
To fix that error you can use the ‘-LargeItemLimit 200 -AcceptLargeDataLoss’ flags (which sounds alarming, but I have not seen it break anything in the last ten years).
Importing PST Files From the Exchange Admin Center
You can import PST files directly in the management GUI > Recipients > Mailboxes > Select the target mailbox > {Ellipses} > Import PST.
Enter the path to the .PST file > Next.
Select the target mailbox > Next.
Optional: Select a user to be emailed an export report.
Note: To view progress and troubleshoot failures, you will have to revert to PowerShell.
How To BULK Import .PST Files
Note: To BULK Import successfully, the .PST file MUST have the same name as the alias of the target mailbox.
Commands Required
1. Once you have created a “Universal Security Group” in this example called “Mailbox_Import” then assign the mailbox import/export roles with the following command;
FailureType : TooManyBadItemsPermanentException Message : Error: This mailbox exceeded the maximum number of corrupted items that were specified for this move request.
This happens when it sees items in the mailbox it does not like, or considers corrupt. To get round this problem, import the .pst file on its own with the following command;
This is not a task I’ve had to do for ages, so when I had to do it this week, I thought I’d just do a quick Google search as a refresher. What I can remember was a simple task took me far too long to work out. So heres a quick solution for everybody else.
Solution
Before I begin, the spreadsheet below, was the hard work of John Haddock, I have only made some minor tweaks and adjustments.
1. You will need the names of the users you want to import in a spreadsheet, preferably with their first name and last names in different columns.
3. On the first tab of the spreadsheet (Setup) enter your domain details, and the other cells as required.
4. Select the second tab (Auto-Generated-Version), and paste your users first-names into column G (Labelled gn for Given Name), and their surnames into column D (Labelled sn).
5. The rest of the fields should now “Auto fill”. To make sure all the user names are unique, look down column V (Duplicate check), and make sure all the entries say “False” if any say “true” you will need to alter the values for that user manually.
6. Once you are happy, select all the columns (Except U and V, {the yellow ones}) and copy them to the clipboard.
7. Select the third Tab (Paste-Your-CSV-Data-Here), Select the entire spreadsheet and Paste Special > Paste Values. (So the formulas DONT get pasted into the spreadsheet).
8. File > Save As > Change the “Save as type” to CSV >Save > OK > Yes.
9. Then at command line issue the following command:
10. All being well it should say “The command has completed successfully” If it does fail it handily tells you what line of the spreadsheet it failed on so you can investigate.
11. By default all the user accounts will be disabled, but you can select them all and enable them.
12. If you would like to reset all the passwords on mass, see the following article:
I’ve written in the past about bulk importing users with CSVDE, but what if you want to move/migrate your users to another domain? You first need to export all the users, then import them into the new domain.
Solution
Step 1 Export Domain Users to CSV File
1. Here all my users are in one OU, if that OU has ‘nested OU’s within it that’s OK.
3. The users will be exported. If it fails at this point it will give you a descriptive error, CSVDE has been around for a while, Google the error (most fixes are pretty simple).
4. Now open the CSV File with Excel, the second line will probably be the OU, you can leave this here if you want but if your target OU is different (or Like me you prefer to create it manually), then delete row 2 (Don’t delete Row 1!).
5. You do not need all the columns, delete all the columns EXCEPT,
DN
objectClass
ou
distinguishedName
name
cn
sn
givenName
displayName
sAMAccountName
userPrincipalName
So when complete it should look like the following;
6. Change any details in the LDAP path that are different for the new domain.
7. You may also need to change the domain name that’s listed on the userPrincipleName.
Step 2 Import Domain Users from CSV File
1. On the target domain, (if you are not importing the OU’s, then make sure they already exist). The syntax for the import is;
[box]
csvde -i -f c:\filename.csv
[/box]
9. Your users should be imported.
10. By default they will be disabled, but you can bulk enable them.
11. At this point all the users have no password, this can also be bulk set.