For years I’ve had a AD user import VBS script as part of my toolkit, I thought it was about time to update it to PowerShell as well as add a few new features. This utility is available to download from the Microsoft TechNet Gallery and GitHub.
If you’d like to get in touch with me please use the comments, Twitter (you can tweet me and my DMs are open) or my contact form. Please consider donating to support my work:
Thank you!
-Mike
Features and Requirements
This utility will create Active Directory user accounts based on information provided in a CSV file. All other options are added via command line switches.
Options include:
- Organisation Unit in which to create the users.
- The UPN that user accounts should have.
- Home Drive location.
- Home Drive Letter.
- Membership of an Active Directory Group.
- Account Expiry Date.
This utility has been tested running on Windows Server 2016 and Windows Server 2012 R2 Domain Controller’s and on a Windows 10 client. This utility requires the Active Directory PowerShell modules to be installed.
The -file Parameter
When running the script via Schedule Tasks or the command prompt be sure to use the -file parameter before specifying the script, so you can use “double quotes” for the command line switches that need them, if you do not use -file, then you should use ‘single quotes’.
CSV File Formatting
The first line of the CSV file should be the column names so the script (and you) know what each column is for.
The structure of the CSV file is as follows:
|
|
Generating A Password File
The password used for SMTP server authentication must be in an encrypted text file. To generate the password file, run the following command in PowerShell, on the computer that is going to run the script and logged in with the user that will be running the script. When you run the command you will be prompted for a username and password. Enter the username and password you want to use to authenticate to your SMTP server.
Please note: This is only required if you need to authenticate to the SMTP server when send the log via e-mail.
|
|
After running the commands, you will have a text file containing the encrypted password. When configuring the -Pwd switch enter the path and file name of this file.
Configuration
Here’s a list of all the command line switches and example configurations.
|
|
The path and filename of the csv file containing the user information to create users from.
|
|
The Organisational Unit to create the users in.
|
|
The Universal Principal Name the users should be configured with.
|
|
The drive letter to use for the home drive path.
|
|
The path where the location of the home drive should reside.
|
|
The DN of a group that all the new users should be made a member of.
|
|
The expiry date of the new users.
|
|
The path to output the log file to. The file name will be AD-Account-Creation-YYYY-MM-dd-HH-mm-ss.log
|
|
The email subject that the email should have. Encapulate with single or double quotes.
|
|
The e-mail address the log should be sent to.
|
|
The from address the log should be sent from.
|
|
The DNS or IP address of the SMTP server.
|
|
The user account to connect to the SMTP server.
|
|
The password for the user account.
|
|
Connect to the SMTP server using SSL.
Example
|
|
This will take information from the users.csv file and create the users in the Imported_Accounts OU. The users home drive will be mapped to W: and be located under \filesrvr01\UserHomes. The users will be a member of the All_Users AD group, will expire 31/07/2022 and will have the UPN of contoso.com. The log will be output to C:\scripts\logs and e-mailed with a custom subject line.
Change Log
2019-09-04 v1.6
- Added custom subject line for e-mail.
2017-10-16 v1.5
- Changed SMTP authentication to require an encrypted password file.
- Added instructions on how to generate an encrypted password file.
2017-10-07 v1.4
- Added necessary information to add the script to the PowerShell Gallery.
2017-09-13 v1.3
- Added check for existence of user before attempting to create user.
- Improved logging to handle the above change.
2017-07-22 v1.2
- Improved code commenting for documentation purposes.
- Added authentication and SSL options for e-mail notification.