Site Maintenance this evening The site will be offline for hosting changes. Time TBC

Find the location of a user account in Active Directory

From Wiki

Revision as of 16:37, 23 June 2008 by SYNACK (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to:navigation, search

Creator: IT Support Staff @ HCHS

Script Language: VBS

Forum topic Link:

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

<vb>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") "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

    			FindUser = rs(0)

else FindUser = "Not Found" end if end if cn.close end function</vb>