LDIFDE export from list of sAMAccountNames, using vbscript

| | Comments (0) | TrackBacks (0)

If you need to export a list of accounts from Active Directory into ldif-format files that will preserve attributes, you can try this. It takes a text list of sAMAccountNames (one per line) and writes out an ldif file for each one. You can easily import the same way by changing the arguments on the exec line and removing the export parameters. You'll also need to fix the line breaks.

'v1.1 ' The script will take a text file with usernames (sAMAaccountNames and export them via ldifde to individual files ' named as sAMAccountname.ldf.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("samaccounts.txt",1)
'On Error Resume Next
Do Until objTextFile.AtEndOfStream
strName = objTextFile.Readline
WScript.Echo "sAMAccountName: " & strName
Set objShell = CreateObject("WScript.Shell")
'you can add/remove attributes from the line below, but be sure to get the quotes right.
Set objScriptExec = objShell.Exec("ldifde -f c:\scripts\export\" & strName & ".ldf -s myDomainController -d ""ou=myOU,ou=Clients,dc=domain,dc=com"" -r ""(sAMAccountName=" & strName & ")"" -l objectclass,dn,c,department,description,displayName,employeeID,extensionAttribute10,extensionAttribute8,extensionAttribute9,givenName,homeDirectory,initials,manager,otherTelephone,physicalDeliveryOfficeName,extension,sn,streetAddress,telephoneNumber,extensionAttribute14,extensionAttribute11,extensionAttribute12,wWWHomePage,sAMAccountName,userPrincipalName,mail,mailnickname,telephoneNumber " )
strResults = objScriptExec.StdOut.ReadAll
WScript.Echo strResults

Loop
set objFile=Nothing

'End

0 TrackBacks

Listed below are links to blogs that reference this entry: LDIFDE export from list of sAMAccountNames, using vbscript.

TrackBack URL for this entry: http://cw.sampas.net/cgi-bin/mt/mt-tb.cgi/163

Leave a comment

About this Entry

This page contains a single entry by Larry published on August 20, 2008 12:29 PM.

Cisco MIB: Interfaces on the 3845 Router was the previous entry in this blog.

How to dump Vonage and save money. is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.