Assigning an smtp email address to an OU

I would like to assign/attach an email address to an OU that would act similiar to a distribution group. Simply put, I have OUs for each of my regions accross the world. When I add a new user object into one of these regional OUs I would like for it to automatically be receiving emails sent to that office.

I realize I could just create a distro group for that OU, but I am trying to automate as much as possible.

If it helps, I am using Active Directory with Exchange 2003.
CogentcoAsked:
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:

You can't assign an address to an OU.

But, you could use a Query-Based Distribution Group with the base of the filter set to that OU. That would keep it nice and up to date.

Otherwise you'd have to script modification of the membership of a standard group on a regular basis, very easy to do if you don't want to play with the Query-Based lists.

HTH

Chris

0
CogentcoAuthor Commented:
Ok, the QBDG is out as we still have one old Exchange 5.5 server on our network (need to be running in native mode for the queries to work). I think that is exactly waht I was looking for too... bummer.

Any ideas as to where I could find a precanned script to accomlish this? My scripting skills are limited to modifying existing ones, not creating them.

Thanks for the input!
0
Chris DentPowerShell DeveloperCommented:

I'll help you do one of those, dead easy to write those for AD :)

Won't be a moment.

Chris
0
Chris DentPowerShell DeveloperCommented:

Here we go.

I'm sure we'll need to play around with it a fair bit before it'll do everything you need.

First things first, what the script does...

You have to configure ROOT_OU, the NETBIOS_DOMAIN_NAME and add the groups you want to use (along with the OU Name) to objOUsToGroups (as in the examples below).

Then the script will connect to ROOT_OU, look for every sub-OU, then for each sub-OU it'll add the user into the respective group (provided it has an entry in objOUsToGroups).

Does that make any kind of sense? :)

Chris
' VbScript to add users to a group based on their Organisational Unit
 
' Information that must be set:
 
Const ROOT_OU = "OU=Root,DC=Domain,DC=local"
Const NETBIOS_DOMAIN_NAME = "YourDomain"
 
' Unless the names of the Groups are going to match the OUs we need to hard-code this lot:
 
Dim objOUsToGroups : Set objOUsToGroups = CreateObject("Scripting.Dictionary")
 
objOUsToGroups.Add "OU 1 Name", "Group 1 Name"
objOUsToGroups.Add "OU 2 Name", "Group 2 Name"
 
'
' Functions
'
 
Function GetObjectDN(strObject, strDomain)
	' Return Type: String
	'
	' Returns a Distinguished Name for an Object from it's NT SAM ID.
	' This will only function for valid object types within an NT Domain structure.
 
	Const ADS_NAME_INITTYPE_GC = 3
	Const ADS_NAME_TYPE_1779 = 1
	Const ADS_NAME_TYPE_NT4 = 3
 
	Dim objNameTranslate
	Dim strObjectDN
 
	On Error Resume Next : Err.Clear
	Set objNameTranslate = CreateObject("NameTranslate")
 
	objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""
	objNameTranslate.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strObject
	strObjectDN = objNameTranslate.Get(ADS_NAME_TYPE_1779)
	If Err.Number <> 0 Then  ' Make the DN Blank for a Failed Search
		strObjectDN = ""
	End If
 
	Set objNameTranslate = Nothing
	On Error Goto 0
 
	GetObjectDN = strObjectDN
End Function
 
'
' Main Code
'
 
Dim objRoot, objOU, objUser, objGroup
Dim strDN
 
' Unless the names of the Groups are going to match the OUs we need to hard-code this lot:
 
' Then connect to the Root_OU
 
Set objRoot = GetObject("LDAP://" & ROOT_OU)
 
' Connect to the Root OU and loop through the sub-OUs
 
For Each objOU in objRoot
	If objOU.Class = "organizationalUnit" Then
 
		' If we have an entry in OUsToGroups we can add the users in that OU to the group
 
		If objOUsToGroups.Exists(objOU.Get("name")) Then
 
			' Try and get the DistinguishedName for the Group so we don't have to 
			' hard-code them all.
 
			strDN = GetObjectDN(objOU.Get("name"), NETBIOS_DOMAIN_NAME)
			If strDN <> "" Then
 
				' Connect to the Group
 
				Set objGroup = GetObject("LDAP://" & strDN)
 
				' Add each User to the Group
 
				For Each objUser in objOU
					objGroup.Add objUser.ADSPath
				Next
 
				Set objGroup = Nothing
			End If
		End If
	End If
Next
 
Set objRoot = Nothing
Set objOUsToGroups = Nothing

Open in new window

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
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
Active Directory

From novice to tech pro — start learning today.