Clean up data and generate unique Windows 2000 server user names
Top  Previous  Next


This script shows how to use Data.Write and string functions to generate properly formatted user names from existing data and how to use Data.Column.DupeCheck to check for forbidden characters and to make sure that AD user names are unique.

Tip: Use the password generator to generate passwords.

Script

[Settings_Begin]
BatchSettings.Delimiter=TAB

SET FirstName=%col1%
SET Initials=%col2%
SET LastName=%col3%
SET FullName=%col1% %col2% %col3%   // create full name from col 1+2+3
SET AccountName=%col4%    // %AccountName% instead of %col4% below = easier to change column
SET Password=%col5%
BatchSettings.MarkerCol=7

SET ADDomainPath=dc=com/dc=acme/dc=D2
SET ADOU=Students
SET ADOUPath=%ADDomainPath%/ou=%ADOU%
[Settings_End]

[Machines_Begin]
\\EDU8      NT PDC    
[Machines_End]

[Init_Batch_Begin]
// Create column 4 from column 1, 2 & 3   
Data.Loop   
 Data.Write 4,lowercase(Copy(%col1%,1,1)%col2%Copy(%col3%,1,2))   
Data.Endloop   
// Check for forbidden character combinations (optional)   
Data.Column.DupeCheck 4,TextFile,w:\words.txt,FindSubStrings   
// Compare with existing common names, add number if same   
Data.Column.DupeCheck 4,CN,edu8.d2.acme.com/dc=com/dc=acme/dc=d2,AddNumber
[Init_Batch_End]

[Batch_Begin]
Data.Loop   
 AD.Account.Create %ADOUPath%,%AccountName%,%AccountName%,%Password%
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,UPN,AccountName%
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,FirstName,ProperCase(%FirstName%)
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,Initials,UpperCase(%Initials%)
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,LastName,ProperCase(%LastName%)
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,FullName,ProperCaseName(%FullName%)
 AD.Account.SetProperty %ADOUPath%/cn=%AccountName%,AccountDisabled,No    
 // Etc
Data.Endloop   
[Batch_End]

[Data_Begin]
anNa      Johnson      pass1
ben      adler      pass2
roger   r   sMith      pass3
cynthiA   L   barnes      pass4
[Data_End]


[Init] section

·Create usernames (common name, UPN and SAM account name) from first letter in first name, initials and first two letters in last name  
·Scan usernames for forbidden character combinations, read about the required text file below.  
·Compare usernames with existing common names on edu8.d2.acme.com and add number if name already exists (this can take a while if there are many accounts)  

[Batch] section

·Create accounts in domain d2.acme.com  
·Combine first name, initials & last name to full name  
·Fix incorrect character case in names  

Text file with forbidden words

"words.txt" example (the script will stop if any username contains "bad", "cat", "dog" or "pet") -

bad
cat
dog
pet


Result from the [Data] row "cynthiA L barnes"