Account server script examples
Top  Previous  Next


·2000 server script  
·NT4 server script  

How the script works


·Get PGP encrypted e-mail attachment*  
·If there are more than one attachment on the e-mail server they are processed in chronological order*  
·Decrypt attachment*  
·Replace slash character ("/") with underscore ("_") in data column 8 (slashes are not allowed in group names)  
·Depending on data in attachment either  
·create account  
·[W2k script only] create OU if needed (OU structure: domain \ unit (school) \ class)  
·create account  
·[W2k script only] set AD properties  
·create group if needed  
·set group membership  
·create home directory (Home directory structure: users \ birth year \ student)  
·set home directory permissions  
·create hidden share  
·print password sheet  
·disable / enable account  
·delete account (The script does not actually delete the account, instead it sets expiration date to January 01, 2000 -> no longer possible to log on, administrator then deletes accounts manually = safety measure! For Windows 2000 it is possible to make things really easy - for an example of how to display a list of accounts for which expiration date has been set to 2000-01-01 for 90 days or more, and if list approved automatically delete the accounts, click here.)  
·move account within a server (change group / [W2k script only] OU)  
·move account to another server  
·If all ok  
·save current data section (good to have if something goes wrong with the password sheets or for debugging purposes)  
·delete current data file (if not deleted it will be run twice)  
·write information event to event log with number of accounts created, enabled, deleted etc.  
·If error  
·write error event to event log  
·send e-mail to administrator  
·save script with current marker position* - possible to retry / continue  
·stop processing of more data files until the error is solved*  

*) Managed by the $GetDataFiles command

Basic properties to modify in the script

·[W2k script only] Domain name = "D2.acme.com" -> [Settings]: "SET ADDomainPath=dc=com/dc=acme/dc=D2".  
·Server name = "\\EDU8" -> [Machines]  
·Root directory for home directories -> [Settings]: "SET HomeRoot=w:\users"  
·Attachments working directory -> [Settings]: "SET DataFilesDir=c:\data"  
·Data section backup directory -> [Settings]: "SET DataSectionBackupDir=c:\databck"  
·Blat install path -> [Settings]: "SET BlatPath=c:\blat"  
·Mail server, e-mail user and password for attachments -> [DataFiles]: "$GetDataFiles" row  
·Mail server and e-mail address for error messages -> [OnError]: "DOS %BlatPath%\blat.exe" row  
·Printer template for Data.PrintRow  

Tips while working on the script

·The contents of the [DataFiles] section and the [Data] section is replaced by the script when you run it - please remember to make any script changes in the original script.  
·Be very careful when evaluating the script; try and verify all possible control field combinations before letting the script run by itself.  
·Do not use the schedule service before the script is fully working:  
·First run the script in GUI mode by clicking the "Run batch" button  
·When everything works in GUI mode, try running the script from the command prompt  
·When everything works from the command prompt, use the schedule service  
·If you are having problems; remove the double backslashes before the "BatchSettings.Debug=Yes" row in [Settings] - this setting causes SetupBatcher to:  
·Show all DOS commands in a dialog before they are executed  
·Run in a GUI window even when called from the command prompt  

How to run the script

The below examples assumes that the script has been saved as "1.cnu" in c:\admwin.

Automatically

·Use the Schedule service to run the script every night at 4:00 am.  
·At the command prompt, type -  

AT 04:00 /interactive /Every:m,t,w,th,f,s,su c:\admwin\admwin.exe /sb c:\admwin\1.cnu /alldata

Manually

·Right-click the desktop, choose new / shortcut. I  
·n the target field type -  

c:\admwin\admwin.exe /sb c:\admwin\1.cnu /alldata

How to display a preview dialog that shows each data file before the file is executed (only meaningful if the script is started manually)

·Add a data.show command to the [Init batch] section, example -  

[Init_Batch_Begin]
Data.Column.ReplaceText 8,/,_ 
Data.Show
[Init_Batch_End]


How to transfer data by FTP instead of by e-mail

·Edit the $GetDataFiles command and set method to FTP  

How to use the script without collecting data from an e-mail or FTP server

·Remove the [DataFiles] section  
·Replace the line "DOS del %DataFilesDir%\%DataFile%" in the [Batch] section with "DOS del w:\data.txt".  
·Add a data.load command to the [Init batch] section, example -  

[Init_Batch_Begin]
$i Data.Load w:\data.txt   
IF %LastErrorCode%<>0 THEN   
 DOS echo %time% %LastErrorMsg% >>%date%.log   
 QuitBatch   
ELSE   
 Data.Column.ReplaceText 8,/,_   
 Data.Show
ENDIF   
[Init_Batch_End]


The above code loads the file "w:\data.txt" into the [Data] section each time the script is executed. If there is no file the script logs the error message in the file "YYYY-MM-DD.log" and quits.