Re: Bulk User Import Using a VBScript

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Using VBScript, you can use ADO and the FileSystemObject to read in a CSV
file, then use a big old loop with variables instead of explicitly defining
your strings.

So oUser.Put "samAccountName", "Jo" would become something like oUser.Put
"samAccountName", strAcctName

Here's some sample code that reads in a CSV file and simply echoes out the
results:

On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\Databases\"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""

objRecordset.Open "SELECT * FROM PhoneList.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
Wscript.Echo "Name: " & objRecordset.Fields.Item("Name")
Wscript.Echo "Department: " & _
objRecordset.Fields.Item("Department")
Wscript.Echo "Extension: " & objRecordset.Fields.Item("Extension")
objRecordset.MoveNext
Loop

For more, see the Scripting Guys' tutorial on ADO and text files:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting03092004.asp

"Mike B." <MikeB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:80C6A12E-C9D2-45CA-A071-F8117177033D@xxxxxxxxxxxxxxxx
> Hi Laura,
>
> Thanks for the quick response.
>
> Basically, I need to add multiple users with a VB Script because I need to
> set UPN & password. I have added one successfully.
> Example below:
> How can I use this VBScript to add multiple users.
>
> Dim oContainer 'Parent container
> of new user Dim
> oUser 'Created user
> 'Get parentcontainerSetoContainer=GetObject("LDAP://OU=marketing,
> DC=reskit,DC=com")
> 'Create user
> Set oUser = oContainer.Create("User","CN=Jo Brown")
> 'Assign properties values to user
> oUser.Put "samAccountName","Jo"
> oUser.Put "givenName","Jo"
> oUser.Put "sn","Brown"
> oUser.Put "userPrincipalName","jo@xxxxxxxxxx"
> oUser.SetInfo
> 'Clean up
> Set oUser = Nothing
> Set oContainer = Nothing
> WScript.Echo "Finished"
>
>
>
> "Laura E. Hunter [MVP]" wrote:
>
>> If you're using ldifde or csvde, then you simply need to add an
>> additional
>> ldif or csv entry for every new user object, and ldifde/csvde will simply
>> loop through the file until it's done. So the command would take
>> something
>> like: (this is obviously greatly simplified)
>>
>> lastname,firstname,username
>> hunter,laura,lhunter
>> smith,joe,jsmith
>>
>> ....and create a new user object for each line item.
>>
>> Or use ldifde for more flexibility in the import process, take a look at
>> this kb for an example: http://support.microsoft.com/?kbid=237677
>>
>> HTH
>>
>>
>> --
>> Laura E. Hunter: MVP Windows Server - Networking
>> All replies to newsgroup, please
>> Post provided as-is, no warranties expressed or implied
>>
>> arnold,mark,marnold
>> "Mike B." <MikeB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:1D12293B-DA83-41F6-8F5D-57388F3B8CDC@xxxxxxxxxxxxxxxx
>> >I have the MS example on how to Import a user into AD. Works great.
>> >What
>> >I
>> > need now is how to import mulitple users (200+) into AD.
>> >
>> > Any ideas?
>> > Thanks,
>> >
>> > Mike B.
>>
>>
>>


.



Relevant Pages

  • Big problem with @array and Chomp ... I think :o
    ... I have a CSV content module. ... can take the contents of a CSV file, paste it into the textarea, and the ... Here is the code I use to add the entry ... Through a loop, I split each ...
    (comp.lang.perl.misc)
  • Re: Looping through File Question
    ... At present I am using this statement to initiate a loop though the ... But you did say you were reading a CSV file, ... for data_row in rdr: ... Here's an example of sucking your data into a list of lists and ...
    (comp.lang.python)
  • RE: Transaction problem between DAO and ADO
    ... do while whatever 'start your loop ... objects opened in ADO. ... Logically I need a new pkID ... dim NewID as long,objMyTable as object ...
    (microsoft.public.access.formscoding)
  • Re: system.Diagnostics.Process Problem
    ... Exit Select ... Loop Until consoleApp.MainWindowTitle.ToString.Length 0 ... then attempt to read the output from the VBScript using ... Hangs because it is looking for the exit of the cmd.exe ...
    (microsoft.public.dotnet.general)
  • Re: system.Diagnostics.Process Problem
    ... If (DateDiff(DateInterval.Minute, objDateTime, DateTime.Now)> 10) Then ... Exit Select ... Loop Until consoleApp.MainWindowTitle.ToString.Length 0 ... then attempt to read the output from the VBScript using ...
    (microsoft.public.dotnet.general)