To edit you must be logged into the site. To login click here
WiKi: Article Discussion History Go to the site toolbox

Find the location of a user account in Active Directory

From EduGeek.Net -> Wiki

Creator: IT Support Staff @ HCHS

Script Language: VBS

Forum topic Link: http://www.edugeek.net/forums/wiki-announcements/17302-find-location-user-account-active-directory.html#post172267

This handy little script will find and display the exact location of a user user account in Active Directory.

domainname=inputbox("Enter DNS Domain Name" & vbcrlf & "(Leave blank for current domain):")
username=inputbox("Enter username:")
 
 
if domainname = "" then
	set objRoot = getobject("LDAP://RootDSE")
	domainname = objRoot.get("defaultNamingContext")
end if
 
if username <> "" then
	wscript.echo finduser(username,domainname)
end if
 
 
Function FindUser(Byval UserName, Byval Domain) 
	on error resume next
 
	set cn = createobject("ADODB.Connection")
	set cmd = createobject("ADODB.Command")
	set rs = createobject("ADODB.Recordset")
 
	cn.open "Provider=ADsDSOObject;"
 
	cmd.activeconnection=cn
	cmd.commandtext="SELECT ADsPath FROM 'LDAP://" & Domain & _
			 "' WHERE sAMAccountName = '" & UserName & "'"
 
	set rs = cmd.execute
 
	if err<>0 then
		FindUser="Error connecting to Active Directory Database:" & err.description
	else
		if not rs.BOF and not rs.EOF then
     			rs.MoveFirst
     			FindUser = rs(0)
		else
			FindUser = "Not Found"
		end if
	end if
	cn.close
end function

Site Toolbox:

This page was last modified 15:37, 23 June 2008. - This page has been accessed 553 times. - Disclaimers - About EduGeek.Net -> Wiki