Omit DN information from csvde results

Posted on 2006-06-06
Last Modified: 2008-01-09
I'm trying to create a csv to import users into a database. I'm using the command below and everything works other than i cannot seem to omit the dn in the results file. Any clues?

csvde -f results.csv -d "ou=users,dc=domain,dc=com" -r (&(obbjectClass=user)(objectcategory=person))" -l "cn,sn,givenName,name,sAMAccountName,userPrincipalName,initials" -o "DN"
Question by:josgan

    Author Comment

    need this answer so i'm increasing the points.
    LVL 70

    Expert Comment

    by:Chris Dent

    DN can't be excluded, it's the unique identifier for the object. You can't delete it afterwards?


    Author Comment

    I want to do a straight import into SQL, and the DN information is messing that whole process up. I'm creating a searchable database users can use to check to see if their account exists.
    LVL 70

    Accepted Solution


    Well all is not lost. It's quite easy to dump that kind of information out with VbScript. There's an example below... you might want to play with the order of the output a little perhaps...

    objRootDSE.Get("defaultNamingContext") gets your domain name, so effectively replaces the dc=domain,dc=com if your CSVDE command above.

    On Error Resume Next


    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFileSystem.OpenTextFile("results.csv", 2, True, 0)

    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"

    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection

    Set objRootDSE = GetObject("LDAP://RootDSE")
    objCommand.CommandText = "SELECT aDSPath, cn, sn, givenName, name, sAMAccountName, userPrincipalName, initials " &_
          "FROM 'LDAP://OU=Users," & objRootDSE.Get("defaultNamingContext") & "'"
    Set objRootDSE = Nothing

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 600
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Cache Results") = False

    Set objRecordSet = objCommand.Execute
    While Not objRecordSet.EOF
          Set objEntry = GetObject(objRecordSet.Fields("aDSPath"))
          strClass = "" : strClass = objEntry.Class

          If strClass = "user" Then
                strCN = "" : strSN = "" : strGivenName = "" : strName = "" : strSAMAccountName = ""
                strUPN = "" : strInitials = ""

                strCN = objRecordSet.Fields("cn")
                strSN = objRecordSet.Fields("sN")
                strGivenName = objRecordSet.Fields("givenName")
                strName = objRecordSet.Fields("name")
                strSAMAccountName = objRecordSet.Fields("sAMAccountName")
                strUPN = objRecordSet.Fields("userPrincipalName")
                strInitials = objRecordSet.Fields("initials")

                objFile.WriteLine strCN & "," & strSN & "," & strGivenName & "," & strName & "," &_
                      strSAMAccountName & "," & strUPN & "," & strInitials
          End If


    Set objRecordSet = Nothing
    Set objCommand = Nothing
    Set objConnection = Nothing

    Set objFile = Nothing
    Set objFileSystem = Nothing

    Author Comment

    Awesome, thanks this does exactly what i need.
    LVL 70

    Expert Comment

    by:Chris Dent

    Pleasure :)


    Featured Post

    New My Cloud Pro Series - organize everything!

    With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

    Join & Write a Comment

    FIPS stands for the Federal Information Processing Standardisation and FIPS 140-2 is a collection of standards that are generically associated with hardware and software cryptography. In most cases, people can refer to this as the method of encrypti…
    Have you ever set up your wireless router at home or in the office to find that you little pop-up bubble in the bottom right-hand corner of Windows read "IP Conflict - One of more computers on the network have been assigned the following IP address"…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now