Solved

ADSI - Trusted Domains - Find user

Posted on 2006-11-21
3
489 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now