[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

ADSI - Trusted Domains - Find user

Hi i need to find user in AD (email, full name )  and as input is domaintname\username

there are 4 domains trees which are trusted.
oldCompany1, oldcompany2, newADDirectory1, newADDirectory2

and i'd like to know how i can find the  user, in any domain without need to  explicitly specify the LDAP connection string for each domain,  
There have to be same list of all trusted trees.


0
winzig
Asked:
winzig
1 Solution
 
inbarasanCommented:
The simple thing you can do is Click on Start--> Search-->Choose "For People"

In that you choose Active directory and give search. It will find.
0
 
winzigAuthor Commented:
But i need perform this operation from script.
I mentioned ADSI because i suppose that  people  in this group are more familiar with this interface, but final code will be written in .NET.

0
 
David LeeCommented:
Greetings, winzig.

This is possible with a bit of fairly simple scripting too.  Something like this:

    Dim varArgument, arrParameters, adoCon, strConnection, adoRS
    varArgument = WScript.Arguments(0)
    If varArgument <> "" Then
        arrParameters = Split(varArgument, "\")
        Set adoCon = CreateObject("ADODB.Connection")
        With adoCon
            .Provider = "ADsDSOObject"
            .Open "Active Directory Provider"
        End With
        strConnection = "SELECT mail, displayName  FROM 'LDAP://" & arrParameters(0) & "' WHERE objectClass='user' AND objectCategory='Person' AND samAccountName ='" & arrParameters(1) & "'"
        Set adoRS = adoCon.Execute(strConnection)
        If Not adoRS.EOF Then
            Wscript.Echo varArgument & " is " & adoRS.Fields("displayName") & vbCrLf & "Email address is " & adoRS.Fields("mail")
        Else
            Wscript.Echo varArgument & " was not found in AD."
        End If
    End If
    Set adoRS = Nothing
    Set adoCon = Nothing

Usage would be

    scriptname.vbs domain\username

Cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now