+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, LDIFDE Syntax in Coding and Web Development; Hi Everyone Trying to use LDIFDE to export users from one particular OU in AD Cant seem to get the ...
  1. #1

    Join Date
    Feb 2008
    Location
    Gloucester
    Posts
    37
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    LDIFDE Syntax

    Hi Everyone

    Trying to use LDIFDE to export users from one particular OU in AD
    Cant seem to get the syntax right.

    Any help would be appreciated Thks

  2. #2

    Join Date
    Jun 2011
    Posts
    12
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Here is what I use to export a report for all the users in a specific OU.
    I have previously used Ldif and DSquery with success, but this vbs export format is perfect as you don't have to do any trimming.

    Bert

    OPTION EXPLICIT

    DIM FileName, multivaluedsep,strAttributes
    DIM strFilter, strRoot, strScope
    DIM cmd, rs,cn
    DIM objRoot, objFSO,objCSV
    DIM comma, q, i, j, mvsep, strAttribute, strValue

    ' ********************* Setup *********************

    ' The filename of the csv file produced by this script
    FileName ="userexport.csv"
    ' Seperator used for multi-valued attributes
    multivaluedsep = ";"
    ' comma seperated list of attributes to export
    strAttributes = "givenName,sn,description"
    'strAttributes = "sAMAccountName,givenName,initials,sn,displayName, description,physicalDeliveryOfficeName," & _
    ' "telephoneNumber,mail,wWWHomePage,cn"

    ' Default filter for all user accounts (ammend if required)
    strFilter = "(&(objectCategory=person)(objectClass=user))"
    ' scope of search (default is subtree - search all child OUs)
    strScope = "subtree"
    ' search root. e.g. ou=MyUsers,dc=wisesoft,dc=co,dc=uk
    ' leave blank to search from domain root
    strRoot = ""

    ' *************************************************

    q = """"

    SET cmd = CREATEOBJECT("ADODB.Command")
    SET cn = CREATEOBJECT("ADODB.Connection")
    SET rs = CREATEOBJECT("ADODB.Recordset")

    cn.open "Provider=ADsDSOObject;"
    cmd.activeconnection = cn

    IF strRoot = "" THEN
    SET objRoot = GETOBJECT("LDAP://RootDSE")
    strRoot = objRoot.GET("defaultNamingContext")
    END IF

    cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & strAttributes & ";" & strScope

    '**** Bypass 1000 record limitation ****
    cmd.properties("page size")=1000

    SET rs = cmd.EXECUTE
    SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
    SET objCSV = objFSO.createtextfile(FileName)

    comma = "" ' first column does not require a preceding comma
    i = 0

    ' create a header row and count the number of attributes
    FOR EACH strAttribute in SPLIT(strAttributes,",")
    objcsv.write(comma & q & strAttribute & q)
    comma = "," ' all columns apart from the first column require a preceding comma
    i = i + 1
    NEXT

    ' for each item returned by the Active Directory query
    WHILE rs.eof <> TRUE AND rs.bof <> TRUE
    comma="" ' first column does not require a preceding comma
    objcsv.writeline ' Start a new line
    ' For each column in the result set
    FOR j = 0 to (i - 1)
    SELECT CASE TYPENAME(rs(j).value)
    CASE "Null" ' handle null value
    objcsv.write(comma & q & q)
    CASE "Variant()" ' multi-valued attribute
    ' Multi-valued attributes will be seperated by value specified in
    ' "multivaluedsep" variable
    mvsep = "" 'No seperator required for first value
    objcsv.write(comma & q)
    FOR EACH strValue in rs(j).Value
    ' Write value
    ' single double quotes " are replaced by double double quotes ""
    objcsv.write(mvsep & REPLACE(strValue,q,q & q))
    mvsep = multivaluedsep ' seperator used when more than one value returned
    NEXT
    objcsv.write(q)
    CASE ELSE
    ' Write value
    ' single double quotes " are replaced by double double quotes ""
    objcsv.write(comma & q & REPLACE(rs(j).value,q,q & q) & q)
    END SELECT

    comma = "," ' all columns apart from the first column require a preceding comma
    NEXT
    rs.movenext
    WEND

    ' Close csv file and ADO connection
    cn.close
    objCSV.Close

    wscript.echo "Finished"



SHARE:
+ Post New Thread

Similar Threads

  1. LDIFDE Export Users
    By barrystone in forum Windows Server 2008 R2
    Replies: 0
    Last Post: 16th June 2011, 05:20 PM
  2. Robocopy syntax
    By jamster69 in forum Scripts
    Replies: 12
    Last Post: 1st October 2010, 03:51 PM
  3. [Fog] Syntax for specifying OU in AD
    By birchanger in forum O/S Deployment
    Replies: 3
    Last Post: 24th July 2009, 05:02 PM
  4. SQL Syntax?
    By ScottStevinson in forum How do you do....it?
    Replies: 2
    Last Post: 8th September 2008, 02:01 PM
  5. LDIFDE Create group command
    By bishopsgarthstockton in forum How do you do....it?
    Replies: 2
    Last Post: 27th March 2007, 02:42 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •