I am trying (rather unsuccessfully) to retrieve a user's home directory path from Active Directory. Users login to my system using their network username; I need to take this username value and retrieve the user's home directory path for it. The code below works, but requires that I know the user's full and last name, and OU path - something which will obviously change.
I can't seem to find any information on how to query Active Directory based on user username, only full name. Could somebody help?
On Error Resume Next
Set objUser = GetObject _
("LDAP://CN=John Doe,OU=Test Users,OU=User Accounts,OU=The Company,DC=domain,DC=internal")
strProfilePath = objUser.Get("profilePath")
strScriptPath = objUser.Get("scriptPath")
strHomeDirectory = objUser.Get("homeDirectory")
strHomeDrive = objUser.Get("homeDrive")
WScript.echo "profilePath: " & strProfilePath
WScript.echo "scriptPath: " & strScriptPath
WScript.echo "homeDirectory: " & strHomeDirectory
WScript.echo "homeDrive: " & strHomeDrive