Generate unique Novell user names and random passwords
Top  Previous  Next


Task

·Create short user names from first two letters in first name and last name  
·Compare user names with existing Novell user names, add number if name already exists  
·Generate random passwords  
·Create accounts  

Script


[Settings_Begin]
BatchSettings.Delimiter=TAB
BatchSettings.MarkerCol=5

SET NDtree=OAK
SET NDpath=%NDtree%\MyOrg\MyOU

SET DataMemFile=c:\N_data.txt
SET NovellAccFile=c:\N_curr.txt

SET FirstName=%col1%
SET LastName=%col2%
SET AccountNameColNo=3
SET AccountName=%Col3%
SET Password=%col4%

Generator.Password.DestCol=4
Generator.Password.Random.Len=8
Generator.Password.Random.Chars=0123456789abcdef
[Settings_End]

[Init_Batch_Begin]
// Save current data section   
Data.Save %DataMemFile%   
// Create file with all existing Novell-accounts   
Data.Get.ND Container,%NDtree%,user,yes,CN§1§   
Data.Save %NovellAccFile%   
// Reload current data section   
Data.Load %DataMemFile%   
// Create user name from first two letters in first name and last name
Data.Loop
 Data.Write %AccountNameColNo%,lowercase(Copy(%FirstName%,1,2)Copy(%LastName%,1,2))
Data.Endloop
// Make user names unique - compare [data] with existing Novell names, add number if same   
Data.Column.DupeCheck %AccountNameColNo%, TextFile, %NovellAccFile%, AddNumber   
// Generate random passwords
Data.Passwords.Generate Random
[Init_Batch_End]

[Batch_Begin]
Data.Loop   
 Nov.DS.Account.Create %NDpath%, %LastName%, %AccountName%, %Password%
Data.EndLoop   
[Batch_End]

[Undo_Batch_Begin]
Data.Loop   
 Nov.DS.Account.Delete %NDpath%, %AccountName%
Data.EndLoop   
[Undo_Batch_End]

[Data_Begin]
Steve   Smith      
Ellen   Jones      
John   Simon      
Lisa   Karush      
Anna   Hedin   
Roger   Palm      
[Data_End]

Result

Data section after first run of above script:

Steve   Smith   stsm   c2a2b7ae   
Ellen   Jones   eljo2   b3d6b0ef   
John   Simon   josi   64071019   
Lisa   Karush   lika   9691915c   
Anna   Hedin   anhe   f5d0da73   
Roger   Palm   ropa   abc039d7   

There was already an account called "eljo" in the directory -> "eljo" became "eljo2".

[Data] section after second run of above script:

Steve   Smith   stsm3   0a580e99   
Ellen   Jones   eljo3   fe74e55d   
John   Simon   josi2   1c752ff4   
Lisa   Karush   lika2   e54158a4   
Anna   Hedin   anhe2   6b6248ba   
Roger   Palm   ropa2   ff554b33   

There was already an account called "stsm2" in the directory -> "stsm" became "stsm3". Trailing number for other accounts increased by one.