vbscript: script assistance


I currently have a vb script that searches for a computer object in the current forest. I want to search for a computer object in a remote forest which is 2-way trust and I have full access. I want to return an attribute called attrib1. Could you please help.

I am logged onto Forest A, I need to search for a computer object in all of the domains in Forest B and return the attribute called attrib1.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nadav SolomonCommented:
you can use powershell cmdlet (first import-module activedirectory)
get-adcomputer -identity computername -server dcFromDomanB -properties attrib1

Open in new window

Another option is to use ADSI
#mind the $ sign after the computer name
$searcher = [ADSISearcher]"(&(objectClass=Computer)(sAMAccountName=computername$))"
$domain = New-Object System.DirectoryServices.DirectoryEntry("dc=domainb,dc=com")
$searcher.SearchRoot = $domain
$computer = [ADSI]$(($searcher.FindOne()).path))

Open in new window

If you want to stick with vbscript post your script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Parity123Author Commented:
How do I search the entire forest (with a few domains) for a computer object and retrieve attrib1
Parity123Author Commented:
This is the vbscript I have:
This works for the current forest, but not for the remote forest. I want to connect to a remote forest and extract data.

Dim Info1
      strServer = "computer1"
      Set objBase = GetObject("LDAP://rootDSE")
      objbase   = "<LDAP://" & oBase.Get("defaultNamingContext") & ">"
      filter = "(&(objectClass=Computer)(objectCategory=Computer)(primaryGroupID=516)(name=" & strserver & "))"
      attr  = "PasswordLastSet"
      scope  = "subtree"

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

      Set cmd = CreateObject("ADODB.Command")
      Set cmd.ActiveConnection = conn
      cmd.CommandText = objbase & ";" & filter & ";" & attr & ";" & scope
      cmd.Properties("Chase referrals") = &h60

      Set rs = cmd.Execute
      Do While Not rs.EOF
            info1 = rs.Fields("PasswordLastSet")
      Msgbox info1
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Nadav SolomonCommented:
your objbase should point to = "<LDAP://frestBDomainController/dc=domainB,dc=com>"
BUT you will probably be able to only search in that domain not the hole forest for 2 reasons.
1) you need to search in global catalog (put GC: instead of LDAP:) the thing is that the attribute you are searching for is probably not indexed into the global catalog.
2) im not sure your trust is transitive (depends on what you choose when you created it).

anyway try it out, maybe it will work.
Parity123Author Commented:
This attribute is not in GC. The  challenge I have is to search the entire forest for object
Nadav SolomonCommented:
Enumerate domains in forest b and search them one by one.
Nadav SolomonCommented:
Glad I could help, thanks for the feedback.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.