Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I know where a user/group/computer is located in my domain?

Status
Not open for further replies.

MahVincent

Technical User
Oct 21, 2001
27
VN
Dear all,

When I find a group/user/computer in "Active Directory Users and Computers" MMC, I can get this object to do many things. However, I don't know where it is, in what OUs, etc... (my domain organization is a little complicated) So I raise a question how to find out the path of an object like user, computer or group? If you know how to that or what tool I need to run and so on, please tell me.

Thanks so much for your help.

Mah Vincent
 
This was a fun one to make. Thanks for asking the question. I've had similar need and this was a good excuse to write the script.

Code:
'==========================================================================
'
' NAME: LocateComputerLDAP.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 3/22/2005
'
' COMMENT: <comment>
'
'==========================================================================


objToFind = InputBox("Enter Computer Name to Locate","What Should I Find?")


ExecuteSearch = SearchDistinguishedName(objToFind)

Public Function SearchDistinguishedName(ByVal vSAN)

Const ADS_SCOPE_SUBTREE = 2
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = oConnection

ldstring = "'LDAP://" & oRootDSE.get("defaultNamingContext") & "'" 

objCommand.CommandText = "Select Name, distinguishedName from "& ldstring & " where objectClass='computer'"  

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30 
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
objCommand.Properties("Cache Results") = False 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
If lcase(objRecordSet.Fields("Name").Value) = lcase(vSan) Then
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value & vbCrLf _ 
    & "Location: " & objRecordSet.Fields("distinguishedName").Value
    'Wscript.Quit
End If
    objRecordSet.MoveNext
Loop
End Function

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
It's great!

I have just edit it and find Computer/user/group. Thanks so much for your assistance.

Mah Vinvent
 
You can find this information without having to run a script. In AD Users & Computers, right-click your domain and select Find. Enter the user name and click Find Now. In the Find Users Contacts and Groups window, click view | choose columns. Select X500 Distinguised Name. A new column appears showing the location of the user account.
 
Thanks so much for all your assistance. Any your suggestions are useful to me.

Mah Vincent
 
You can also use dsquery for this:

dsquery user -limit 300 |find /I "usernamehere
 
NOTE: dsquery is only available with Windows 2003 Server or if you are running Windows XP Pro with Windows 2003 ADMINPAK.MSI installed. You can run this tool from a XP Pro desktop with the Adminpak installed over a Windows 2000 Server installation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top