No announcement yet.

dsget Problem with contacts & users in same OU

  • Filter
  • Time
  • Show
Clear All
new posts

  • dsget Problem with contacts & users in same OU

    I recently upgraded our domain to 2003, and have one 2003 domain controller so I can use dsget & dsquery for exports (I briefly tried making them work under 2000, and decided it was past time to upgrade, anyway).

    What I need is an export of the names and email addresses for everyone in two distribution groups. Using the Active Directory Export Sticky as a guide, I've managed to get this far:

    The first one is easy:
    dsget group "CN=DistGroup1,OU=Child,OU=Parent,DC=ourdomain,DC= net" -members -expand | dsget user -display -Email > c:\exports\test.txt


    Now it gets more difficult. The second distribution group I want an export from is in the same OU, but has three nested groups inside it, and one of those has two nested groups inside it. Since it's a small number of groups, I decided to do a workaround by just running a separate query for each group. (If anyone knows of a way to drill directly to the end users by querying the top distribution group, that would be great).

    Here's the actual problem that I can't find a workaround for:
    In two of my nested groups, I have both Active Directory User objects and Active Directory Contact objects (SMTP contacts we need in our Exchange address book, but don't want user accounts for).

    So I run:
    dsget group "CN=DistGroup4,OU=Child,OU=Parent,DC=ourdomain,DC= net" -members -expand | dsget user -display -Email > c:\exports\test4.txt

    and I get this:
    dsget failed:CN=Jane Doe,OU=Our_Contacts,OU=Users_OU,DC=ourdomain,DC=ne t:The object class of the target does not match the one specified on the command line.

    In this case, Jane Doe is a Contact object (not a user object). (She's in an OU that's entirely separate from the OU the distribution groups are in.) For some reason, it does go ahead and export a few, but not all, of the User objects.

    So I run:
    dsget group "CN=DistGroup4,OU=Child,OU=Parent,DC
    =ourdomain,DC=net" -members -expand | dsget contact -display -Email

    and I get this:
    dsget failed:CN=John Doe,OU=Our_Sites,OU=Users_OU,DC=ourdomain
    ,DC=net:The object class of the target does not match the one specified on the command line.

    John Doe is an Active Directory User object. None of the contact objects export.

    To recap:
    1. Is there a way to export all the users with the nested distribution group setup that I have?

    2. Is there a way to export all the users AND contacts in a single distribution group (I could work around by putting all contacts into a group and nesting that group, but that's really messy, and may not be do-able due to our OU and grouping structure)

    3. Minor issue, but somebody might have an answer. When I redirect the dsquery/dsget output to a text file (with > export.txt), it overwrites the file with each new query. If there's a way to append to the same file, instead of creating separate output files and combining them later), that would be nice to know.

    Perhaps I need a different tool than dsquery/dsget? I'm sure some VB scripting would solve my question number 3, but I have no VB scripting experience. The best I can do is sometimes hacking things together if I can find enough example code that's nearly what I'm trying to do.

    Thanks in advance for any help y'all can give me.


  • #2
    Re: dsget Problem with contacts & users in same OU

    Run dsget with "-c" switch (will continue on errors) and redirect STDERR to NUL


    dsget blah blah -c 2>NUL > test.txt
    Guy Teverovsky
    "Smith & Wesson - the original point and click interface"


    • #3
      Re: dsget Problem with contacts & users in same OU

      Thanks guyt; that ought to take care of it. Guess I should have read through those switch options in Microsoft's 2003 online help a little better.

      We ended up running two simple dsquery commands, one for users, and one for contacts, in all OU's. Then our Access guru pulled them in and set up a query to pull out only the people in the distribution groups we were wanting. Not quite as clean for getting just a list, but as it turns out, they were wanting the list so they could import it into Access anyway.

      Thanks again....