Mass creating users using PowerShell and PowerGUI from Quest

DISCLAIMER: Use on your own risk. My company and I will not be responsible any actions and/or results this script may cause. All user names are fictious.

This script can be used to create multiple users using powershell along with PowerGUI from Quest with Active Directory module installed. To use this script, first create a csv file using excel or notepad as follows:

FirstName,Initials,LastName
John,S.,Smith
Jane,,Johnson
Anthony,H.,Do
Ari,,Zeckinson
Aydin,,Valare
Ben,,Franklin
Benson,,Cheng
Cassie,,Doyle

or

Once the file is created, save it in c:\temp\new-users.csv, copy and paste the PowerGUI script editor and run. Once user account has been created, Set-QADUser will set the account to require to change password as first logon.

Comments and questions are welcome.

# ————————- SCRIPT BEGINS ——————————-# ——————————————# – Script used to mass create users in AD -# ——————————————
#Prompting for default password.$pw = read-host “Enter password” -AsSecureString

#Importing user information from new-users.csv

$newuser= import-csv C:\temp\new-users.csv$OU= ‘OU=Dev,OU=IT,OU=Users,OU=Los Angeles,DC=nguyen,DC=local’
foreach ($line in $newuser) {

#Setting SAMAccountname name to first initial + lastname. Example: Peter Nguyen would be pnguyen $SamAccountName = $line.FirstName.Substring(0,1) + $line.LastName

#Setting UPN

$UPN = $SamAccountName + ‘@nguyen.local’
#Echo SamAccountName $SamAccountName
#Checking to see if Initial Field is empty, if so create username without initial

If ($line.Initials.Length -eq 0) { $Name = $line.FirstName + ‘ ‘ + $line.LastName

New-QADUser -ParentContainer $OU -name $Name -SamAccountName $SamAccountName -UserPrincipalName $UPN -FirstName $line.FirstName -LastName $line.LastName -UserPassword $pw Set-QADUser $SamAccountName -UserMustChangePassword $true }

#If Initial field in csv file is not empty then create user with an initial

Elseif ($line.Initials.Length -gt 0) {

$Name = $line.FirstName + ‘ ‘ + $line.Initials + ‘ ‘ + $line.LastName New-QADUser -ParentContainer $OU -name $Name -SamAccountName $SamAccountName -UserPrincipalName $UPN -FirstName $line.FirstName -Initials $line.Initials -LastName$line.LastName -UserPassword $pw

Set-QADUser $SamAccountName -UserMustChangePassword $true
}}

# ———————— SCRIPT ENDS ————————

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s