Do not post any licensing information in this forum.
The script that I have is part of a SQL job. The job runs the script and I didn't realize that the entire script wasn't posted.
I'm going to update the post, I was trying to edit it, but I don't see that option.
I am new to VB and also SQL jobs that run scripts, so I appreciate the help.
This is the T-SQL script that sets up your linked server. Using this you can query and update tables using a simple task trigger. This is more secure and much faster than using the very old VBScript methods.
Code: Select all
--Create a Linked Server
EXEC sp_addlinkedserver @server = 'ADSI', @srvproduct = 'Active Directory Services 2.5', @provider = 'ADSDSOObject', @datasrc = 'adsdatasource'
--Configure the server to allow OPENQUERY functions
sp_configure 'show advanced options', 1
reconfigure with override
sp_configure 'Ad Hoc Distributed Queries', 1
#EXEC sp_addlinkedsrvlogin @rmtsrvname = 'ADSI', @useself = 'true'
SELECT * FROM OpenQuery(
ADSI, 'SELECT * FROM ''LDAP://DC=<your domain>,DC=<your domain>'' WHERE objectCategory=''User''')
1- This script runs within a SQL job on a 2008 sql server.
2- It retrieves AD data and populates a SQL DB with that data
3- It functions fine using the entire code below, this was written by a SQL DBA a few years ago and I was able to add a couple user attribs to it.
4- Now the request is to add the sAMAccountName of each users Manager to the list of items populated in the database. I am not sure how to retrieve that as I can get the Managers DN, but that's easy as I have found.
the code is below, any help would be very appreciated
- (6.59 KiB) Downloaded 191 times
just use the code to get the manager.
Can you tell me where in the script the code has to go and also I assume I need to add in a line that adds the name to the sql record set?
I do not see in your code where you have assigned the manager.
VBScript CodeDouble-click the code block to select all.
Set mgr = GetObject("LDAP://" & rs.Fields("manager") )
The message box isn't going to help me, this is supposed to run as a scheduled job that involves no interaction.
Thanks for the help though, I'll do something else.
Just assing the field to the results of the mgr.SAmaccountName
rs.Field("manager") = mgr.SamAccountName
Who is online
Users browsing this forum: No registered users and 2 guests