Solved

ADSI - Trusted Domains - Find user

Posted on 2006-11-21
3
523 Views
Last Modified: 2008-01-09
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
Comment
Question by:winzig
3 Comments
 
LVL 14

Expert Comment

by:inbarasan
ID: 17986820
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
 
LVL 10

Author Comment

by:winzig
ID: 17988952
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
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17989424
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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