Solved

LDAP Query of manager and update manager

Posted on 2008-10-24
3
2,134 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:ksb-sys
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 125 total points
ID: 22802579

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
 

Author Comment

by:ksb-sys
ID: 22813269
Perfect! Thank yoU!!!
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 22813288

You're welcome :)

Chris
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Insert with SET how to handle join 6 69
Update in Sql 7 37
VIDEO DATASOURCE Control Resize issue 2 15
T-SQL Default value in Select? 5 22
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now