Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory Users 2

Status
Not open for further replies.

QKSTechTrainee

IS-IT--Management
Jan 19, 2004
3
0
0
GB
Anyone know how to use a VBscript to gain access to a user in the active directory and make changes to their details?

I have been reading about LDAP: but seem to be missing some important bit of info because all my attempts fail - is there some other way to get at these?

Our Active Directory contains a number of user OU's, all contained within another OU (can I also access this as a container?) which is again held inside another OU. I don't seem to be able to phrase an LDAP: query that will traverse down this tree of OU's to the target OU containing user entries.

I think of the LDAP: query with this structure - domain\UsersRootOU\UsersSubSetOU\UsersSubSubSetOU\users - is this how it works?

I want to iterate through each user held within the OU's contained within UsersSubsetOU - capture some details, check these against a database (well spreadsheet actually, but nobody's perfect) capture other details from the spreadsheet and write these back out to the user details. So far I can get everything to work fine except for actually accessing the user account details. I am running this with full administrative priveleges on a Win2k Server Advanced system (workstations are XP Pro but that shouldn't matter, should it? Anyone know of any issues with this combo?) Having said that I'm not terribly sure about the modifications to the user accounts... ;-)

Anyway - thats it - sorry bout the mammoth post - bye

 
The correct way to path with LDAP to bind to an objet would be.

"LDAP://cn=user,ou=FirstOU,ou=SecondOU,dc=firstLevelDomain,dc=TLDomain"

My recomendation would be to bind to the OU gather all of the users in the OU into an array then perform whatever compare functions.

HTH,

Z
 
OK - I have used LDAP: to bind to the object I want to use - now - how do I change a property of this object and return the object to the AD (for example - having used :

for each user in objUsers
strDName = user.displayname

'I want to set user.description to the value of strDName
' user.description = strDName does NOT work
'

next


Anyone know how to do this?
 
I think i documented below enough of the code that you should be able to figure out what is going on. This may or may not help you.

John


Code:
'Set constants for files
Const ForReading = 1
'Set up for error handling later
On Error Resume Next
'Set up the input file and make sure the argument for the file
'has been included within the execution
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF Wscript.Arguments.Count = "0" Then
   'if no file name for input file in execution path give warning and quit
   msgbox "Please Enter UpdateTest.vbs nameoftext file to read" & vbcrlf & "Example UpdateTest.vbs a:\update.txt"
   wscript.quit
End If
'get the file path from the arguments in the execution of file
TextFile = wscript.arguments(0)

'If file does not exist at that path quit
if objfso.fileExists(textFile) = False Then
   msgbox "Unable to find Input FIle"
   wscript.quit
end if
'Open up file for reading only
Set objTextFile = objFSO.OpenTextFile (textFile, ForReading)
set outputFile = objFSO.OpenTextFile ("C:\ErrLogUp.txt",2,True)
'Do until end of file
Do Until objTextFile.AtEndOfStream
	'Read the lines one at a time and put the information into array
	strNextLIne = objTextFile.Readline
	arruserList = Split(strNextLine , ",")
	Name = arruserList(0)
	telep = arruserlist(1)
	dept = arruserlist(2)
	location = arruserlist(3)
	title = arruserlist(4)
	manager = arruserlist(5)
	manloc = arruserlist(6)

'Get the correct user ready for update
Set objUser = GetObject _
   ("LDAP://cn=" & name & ",ou=madison,ou=accounts,dc=gehl,dc=com") 
'Make sure name exists in active directory
If Err.number <> 0 Then
    OutPutFile.WriteLine &quot;Error For &quot; & name & &quot; Description: &quot; & Err.Description 
    Err.Clear
Else
'Put in the changes that need to be made 
objUser.Put &quot;telephoneNumber&quot;, telep
objuser.put &quot;department&quot;, dept
objuser.put &quot;l&quot;, location

'String together the manager name and location 
'so it can pick it out of active directory
strManager = &quot;cn=&quot; & manager & &quot;,ou=&quot; & manloc & &quot;,ou=accounts,dc=gehl,dc=com&quot;

objuser.put &quot;manager&quot;, strManager
objuser.put &quot;title&quot;, title
'Apply the new info into active directory
objUser.SetInfo
End If
Loop
'close the files
OutPutFile.Close
objTextFile.close
set objTextFile = Nothing
Set OutPutFile = Nothing
'send message so know that it is complete
msgbox &quot;Processing Complete&quot;
 
Thanks very much guys - this has sorted out all my problems I think. Don't despair though - I'm pretty sure there'll be more :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top