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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active directory question 5

Status
Not open for further replies.

rdfdr78

Technical User
Jul 19, 2005
94

Hello,

Within AD 2003 how do you get users profile`s within an OU to update the department field with the correct field, So for instance the account`s OU anyone within this OU would automatically get assigned the correct Department field of Accounts Dept.

Help Appreciated

Richard
 
I don't believe AD natively has an automatic function to do this. However, if you highlight all users in the OU and select the properties you will have this option under the Organization tab. Check Department and enter your string.

More so, if you setup a template user with this field already populated you can copy this user when setting up new users. The only downfall to this, if a user moves into a new department this will need to be modified manually.

Otherwise, you will need a script it. I'll bet markdmac will chime in on that [smile]

Hope This Helps,

Good Luck!
 
I'm not aware either of an automatic way of doing it without scripting it in vbs.

I've just installed yet another instance of DirectoryUpdate so that users can update their own info.
Works great.

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Want to know how email works? Read for yourself -
 

Thanks guys for your input.

I`d really like to get it done properly however Scripting is not a strong point. How easy would it top do a script for a complete novice?

Are there any scripting guru`s out there that can help?

Help Appreciated

 
I'm sure Mark will chip in at some point with a script or you could post in the VBscript forum.

Are you sure ADModify will not do this i've just looked and it seems that it will and it should make the change so future users will pick it up.





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 
I`ve just tried creating a new user from scrathc within "test" however when i went to Department name it did not pick up "Test department", am i doing something wrong?
Or is it a case if i create a user from a template and move it into that folder it will pick up the new setting automatically?
 
Have you used Admodify to alter users in an OU?





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 
Bascially have run ADmodify has picked all the OU`s with users, i then click the Correct OU then click add to list which the proceeds to move all users across, then i configure the Departments Tab which then succesfully changes all the users. However if i add a user to the accounts OU the Department field does not get amended? or do i need something else?
 
It seems that this is not something that can be added in this way, now that you have altered all of the current users you should use a template to create new users as you suggested.





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 

Ok thank`s for your help Porkchopexpress!

Richard
 
No prob

Like i say someone in the VB forum might be able to help but i don't think it's an attribute that can be set by moving a user to an OU.





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 
My test server hard drive died before I had time to put in the replacement drive (I knew it was old and had one ready to go) so I don't have access to my server at the moment, but if you can give me a day or two I would be happy to script it.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Thanks Mark any help would be appreciated.

Richard
 
OK guys. Be prepared for what I am willing to say is one of the COOLEST scripts I have written. The code itself is nothing all that special but it is the implementation of it that will totally blow your socks off. I've recently been playing with Display Identifiers in AD. This is the ability to add right click menu choices for AD objects.

I have a script to reboot computers with a right click from AD as an example.

So here is the script that rdfdr78 needed. Follow the implementation instructions in red. You will then be able to right click any OU that you have created and select Set Department. From there you will be prompted for a department name and it will set all users below that OU to have that department.

Code:
[green]
'==========================================================================
'
' NAME: SetDepartmentFromOU.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]	
' COPYRIGHT (c) 2006 All rights reserved
' DATE  : 11/10/2006
'
' COMMENT: 
'[/green][red]
'    This is one cool script.  To implement it do the following.
'    1. Place this script in the same folder on the hard drive of all domain controllers
'    2. Open ADSIEdit
'    3. Connect to the Configuration Context
'    4. Expand out Configuration/Configuration/Display Specifiers/CN=409
'    5. Right Click CN=organizationalUnit-Display Choose properties
'    6. Click Admin Context Menu
'    7. Click Edit
'    8. Type [b]3,Set Department,C:\Scripts\SetDepartmentFromOU.vbs[/b]
'       (note to change the path to the folder and name to match your script location)
'       The number 3 indicates the position the menu item will appear.  If you want it first
'       you can rename the other entries first to increment their menu orders then add this line
'    9. Click Add, OK, OK
'   10. Close ADUC and ADSIEdit
'   11. Open ADUC and right click the OU you wish to set Department value for. Select Set Department.
'[/red][green]
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'=====================================
[/green]
On Error Resume Next

strDN = Wscript.Arguments(0)

strDepartment = InputBox("Enter Department Name", "Department Name to Set")
[green]
' Use ADO to search the OU for users.[/green]
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection


strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = "<" & strDN & ">;" & strFilter _
  & ";distinguishedName;subtree"


objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
[green]
' Enumerate users. Grab each user's Distinguished Name [/green]
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
  strUserDN = objRecordSet.Fields("distinguishedName")
[green] 'Bind to the user and set the department[/green]
	Set objUser = GetObject("LDAP://" & strUserDN)
	objUser.Put "department", strDepartment
	objUser.SetInfo
  objRecordSet.MoveNext
Loop

MsgBox "Department Value Set for " & strDepartment & " users."

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Does this automate anything? If I move a user from one OU to another, will the Department attribute change automatically with this implementation?
 
No it will not be automatic but simple enough to right click again. to enumerate through each of the users in the OU again.

If you are looking for it to be automatic, then I would suggest using a script for the actual move so you could perform the update at the same time.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Nice one Mark. He's back.





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top