LDAP Query of manager and update manager

I'm on a quest to update an employee's supervisor in AD.

I've got the part where we're querying the user's manager all set. But as soon as I query the adspath of the manager to put that into the user's manager field in their AD record, I get an error 80005008 at Line 49 which is:
            if usrmgr <> "" then usr.put "manager", usrmgr
Any ideas why this would be happening?

Thanks
Call Run_SetManager
 
Function Run_SetManager
 
set conn = CreateObject("ADODB.Connection")
set rsExch = CreateObject("ADODB.Recordset")
set rsADUsr = CreateObject("ADODB.Recordset")
set rsADMGR = CreateObject("ADODB.Recordset")
Set oCmd = CreateObject("ADODB.Command")
Set oCmd1 = CreateObject("ADODB.Command")
 
conn.Open "Data Source=Active Directory Provider;Provider=ADsDSOObject"
 
uname = inputbox("Enter the FULL NAME of the user to modify:", "Enter Username")
 
If uname = "exit" Or uname = "" Or uname = "Exit" Then 
Exit Function 
End If 
 
if uname <> "" then
	strADOQuery = "SELECT adspath, manager, title from 'LDAP://pathtodomain'' WHERE objectCategory='person' AND objectClass='user' AND name = '" & uname & "'"
	oCmd.ActiveConnection = conn
	oCmd.Properties("SearchScope") = 2
	oCmd.CommandText = strADOQuery
		
	set rsADUsr = oCmd.Execute
	if rsADUsr.RecordCount = 0 then msgbox "Username not found."
	if rsADUsr.RecordCount > 1 then msgbox "Multiple names found. This script can't help you."
	if rsADUsr.RecordCount = 1 then
		set usr = GetObject(rsADUsr.Fields("ADsPath"))
		if isnull(rsADUsr.Fields("manager")) = true then current = ""		
		if isnull(rsADUsr.Fields("manager")) = false then current = rsADUsr.Fields("manager")
		URL = inputbox("DO NOT PRESS CANCEL. PRESSING CANCEL WILL ERASE THIS ATTRIBUTE." & vbcrlf & vbcrlf & "Change Manager for " & uname & " to:", "Change Manager")
				strADOQueryMGR = "SELECT adspath from 'LDAP://pathtodc' WHERE objectCategory='person' AND objectClass='user' AND name = '" & URL & "'"
				oCmd1.ActiveConnection = conn
				oCmd1.Properties("SearchScope") = 2
				oCmd1.CommandText = strADOQueryMGR
					
				set rsADMGR = oCmd1.Execute
				if rsADMGR.RecordCount = 0 then msgbox "Manager not found."
				if rsADMGR.RecordCount > 1 then msgbox "Multiple managers found. This script can't help you."
				if rsADMGR.RecordCount = 1 Then 
					set usrmgr = rsADMGR.Fields("adspath")
				end if
 
		if usrmgr <> "" then usr.put "manager", usrmgr
		if usrmgr = "" then usr.Putex 1, "manager", ""
		usr.SetInfo
		msgbox "Manager Update Successful"
		set usr = nothing
	end if
end If
 
 
 
conn.close
set ocmd = nothing
set ocmd1 = nothing
set rsExch = nothing
set rsADUsr = Nothing
set rsADMGR = nothing
set conn = nothing
 
End Function

Open in new window

ksb-sysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

Hey :)

Add distinguishedName into here:

>         strADOQuery = "SELECT adspath, manager, title from 'LDAP://pathtodomain''
> WHERE objectCategory='person' AND objectClass='user' AND name = '" & uname & "'"

e.g.

strADOQuery = "SELECT adspath, manager, title, distinguishedName from 'LDAP://pathtodomain' " &_
  "WHERE objectCategory='person' AND objectClass='user' AND name = '" & uname & "'"

Then change this:

> set usrmgr = rsADMGR.Fields("adspath")

To:

usrmgr = rsADMGR.Fields("distinguishedName")

ADSPath includes LDAP:// which isn't valid for the manager field. Set is unnecessary as it's just a string value, not an object.

HTH

Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ksb-sysAuthor Commented:
Perfect! Thank yoU!!!
0
Chris DentPowerShell DeveloperCommented:

You're welcome :)

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.