Announcement

Collapse
No announcement yet.

Search in a forest with 7 domains

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search in a forest with 7 domains

    I want to search for a user account in a forest with 7 domains.

    When I use the code below it will just find the account if it is in one specific domain,

    I want to find the account regardless of which domain in the forest it is in.


    Set oRootDSE = GetObject("LDAP://RootDSE")
    sDomainADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
    Set oRootDSE = Nothing

    Can someone help me with this?

  • #2
    Re: Search in a forest with 7 domains

    Hi,

    Use GC instead of LDAP.

    It should look like GC://"Sourece Path"

    Regards,
    Kapil Sharma
    ~~~~~~~~~~~~~
    Life is too short, Enjoy It.

    Comment


    • #3
      Re: Search in a forest with 7 domains

      You should have posted it in "Scripting" section rather then "Active Directory".

      Regards,
      Kapil Sharma
      ~~~~~~~~~~~~~
      Life is too short, Enjoy It.

      Comment


      • #4
        Re: Search in a forest with 7 domains

        Ok sorry my first time here, I will be better at this, I can't move this now?.

        I have tried GC but then I get no access at all.

        Set oRootDSE = GetObject("GC://RootDSE")
        sDomainADsPath = "GC://" & oRootDSE.Get("defaultNamingContext")
        Set oRootDSE = Nothing

        I really dont know what to do.

        Comment


        • #5
          Re: Search in a forest with 7 domains

          It goes like this:

          GC://root domain name.

          For more ref check this:

          http://msluder.dk/Resources/ADSI%20S...%20HTML/ad.htm

          Regards,
          Kapil Sharma
          ~~~~~~~~~~~~~
          Life is too short, Enjoy It.

          Comment


          • #6
            Re: Search in a forest with 7 domains

            Moved to Scripting for better response
            Tom Jones
            MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
            PhD, MSc, FIAP, MIITT
            IT Trainer / Consultant
            Ossian Ltd
            Scotland

            ** Remember to give credit where credit is due and leave reputation points where appropriate **

            Comment


            • #7
              Re: Search in a forest with 7 domains

              Do not use the "defaultNamingContext", use "rootDomainNamingContext"
              Then use the "LDAP:" provider instead of "GC:" (this will give you the possibility to include also attributes in the "objCommand.CommandText" that are not replicated to the Global Catalog).

              Enumerate the domains and search in each separately.

              I found this example:
              Code:
              Set objRootDSE = GetObject("LDAP://rootDSE")
              ' strRootAdsPath = "GC://" & objRootDSE.Get("rootDomainNamingContext")
              strRootAdsPath = "LDAP://" & objRootDSE.Get("rootDomainNamingContext")
              
              Set objConnection = CreateObject("ADODB.Connection")
              objConnection.Open "Provider=ADsDSOObject;"
              Set objCommand = CreateObject("ADODB.Command")
              objCommand.ActiveConnection = objConnection
              objCommand.Properties("Page Size") = 500
              
              objCommand.CommandText = "<" & strRootAdsPath _ 
                 & ">;(&(objectCategory=computer))" _
                 & ";ADsPath,name,distinguishedName;subtree"
              
              Set objRecordSet = objCommand.Execute
              
              If objRecordSet.EOF Then
               WScript.Echo "No Computer found with that name"
              Else
               WScript.Echo "Computer Name" & vbTab & "OS" & vbTab & "AD Path"
               Do Until objRecordset.EOF
                strLDAP ="LDAP://" & objRecordset.Fields("distinguishedName")
                Set objComputer = GetObject(strLDAP)
                WScript.Echo objRecordset.Fields("name") & vbTab _ 
                   & objComputer.operatingSystem & vbTab _
                   & objRecordset.Fields("distinguishedName")
                objRecordset.MoveNext
               Loop
              End If
              
              objConnection.Close
              The script above is searching computerobjects (&(objectCategory=computer)) (see the "objCommand.CommandText"),
              if you want to find Userobjects then search for (&(objectCategory=person)(objectClass=user)) - and choose the user attributes you want to see in your results.

              here is an other example:
              "DocumentForest.vbs"

              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X