Creating a User from File Data


Now that we have stepped through some very basic scripts, we can start tackling more complicated tasks such as creating users from file data. When data is presented to IT personnel for the purpose of creating several user accounts, this data can be referenced and used to help automate user creation. Commonly used file formats include LDIF-compatible files, comma-separated value (CSV) files, and tab-separated value (TSV) files. Files can be read with VBScript using the File System Object (FSO) model. If the files are presented in LDIF or CSV format, the data can be cleaned up and used to create users in Active Directory using either the Ldifde.exe tool or Csvde.exe tool, respectively. Also, if the data necessary to create the directory object is stored in a database or a separate directory, the data can be retrieved using ActiveX Data Objects (ADO) provided that ADO can bind to the database.

Using Ldifde.exe or Csvde.exe

Ldifde.exe and Csvde.exe are both great tools for creating directory objects using clean formatted data presented in LDIF or CSV format. As export tools, their functionality includes exporting data based on location in the directory, OU membership, and object class such as user, group, or computer; they also specify which attributes to export. As far as specifying certain attributes, these tools are fairly limited, but for one-time mass user export and import scripts, they can add value to directory management. To use Ldifde.exe to create an export file of every object in the Users container of Companyabc.com, follow these steps:

1.

Log on to a workstation or server in the Companyabc.com domain with an account that has Domain Admin rights.

2.

Choose Start, Run.

3.

Type cmd.exe and click OK to open a command prompt.

4.

Type the following command and press Enter to execute it:

ldifde -f UserContainer.txt d "cn=users,dc=companyabc,dc=com"


This command creates a file containing all the attributes and values of the User container and all the objects within it.

5.

To open the output file to see what the LDIF format looks like, in the command-prompt window, type the filename to open it in Notepad.

You also can use these tools to perform directory imports if necessary. One limitation is that you cannot set the initial password using these tools.

Connecting to Flat File Data Sources

You can connect to flat files with pure VBScript commands. Using the File System Object model, you can complete file read and write operations.

Files can be opened for reading, writing, or appending to an existing file. When files are opened for reading, the data can be read one character at a time, line by line, or the entire file can be opened and loaded into memory. As an example, the following script will read the boot.ini file of a Windows Server 2003 server; it will then read one line at a time and output that information to the console in a message box until the file reaches the "end of file marker" triggering a final message to be sent.

Dim FSO, TheFile, Line Set FSO = CreateObject("Scripting.FileSystemObject") Set TheFile = FSO.OpenTextFile("C:\boot.ini", 1) Do While NOT TheFile.AtEndOfStream Line = TheFile.ReadLine MsgBox Line Loop MsgBox "The end of the file has been reached." 


This script creates a File System Object based on the boot.ini file. The script reads a single line and outputs it to the screen for each line in the file until the file reaches the end. At that point, a confirmation pop-up window states that the end of file has been reached.




Microsoft Windows Server 2003 Unleashed(c) R2 Edition
Microsoft Windows Server 2003 Unleashed (R2 Edition)
ISBN: 0672328984
EAN: 2147483647
Year: 2006
Pages: 499

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net