Sign in to follow this  
Followers 0
swalsh19

Automating the addition of Exchange Distribution Groups

13 posts in this topic

I have a tool created that will create users in AD. Is it possible to do the following:

- automatically add a distribution group to the user upon creation

- automatically add the distribution group that corresponds to the office of the user.

Here is what the gui looks like that I have.

Posted Image

Share this post


Link to post
Share on other sites



If you use the ADfunctions you could use ADAddUserToGroup for adding users to groups.


"Human kind cannot gain anything without first giving something in return, to obtain; something of equal value must be lost."The Help File is truly your friend.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

erased as it posted twice.

Edited by swalsh19

Share this post


Link to post
Share on other sites

Here is the code I have.....

; example 1

include <GUIConstants.au3>

GUICreate("Filogix New User Creation",500,200) ; will create a dialog box that when displayed is centered

$FirstName = GUICtrlCreateInput("",70,5,200,20)

GUICtrlCreateLabel ("First Name",10,9,50,20)

$LastName = GUICtrlCreateInput("",70,40,200,20)

GUICtrlCreateLabel ("Last Name",10,42,55,20)

$Office = GUICtrlCreateCombo ("",340,5,100,20)

GUICtrlSetData(-1,"London Office|Toronto Office|Calgary Office","London Office")

GUICtrlCreateLabel ("Office",305,9,30,20)

$Extension = GUICtrlCreateInput("",340,40,55,20)

GUICtrlCreateLabel ("Extension",287,42,50,20)

$Title = GUICtrlCreateInput("",70,75,200,20)

GUICtrlCreateLabel ("Title",40,77,25,20)

$Department = GUICtrlCreateInput("",70,110,200,20)

GUICtrlCreateLabel ("Department",7,112,55,20)

$CreateUser = GUICtrlCreateButton("Create User", 70,140,70,30,$BS_DEFPUSHBUTTON)

$Clear = GUICtrlCreateButton("Clear",150,140,70,30,$BS_DEFPUSHBUTTON)

$Exit = GUICtrlCreateButton("Exit",230,140,70,30,$BS_DEFPUSHBUTTON)

GUISetState (@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $Clear

Call ("Clear")

Case $msg = $CreateUser

Call ("CreateUser")

Case $msg = $Exit

Exit

EndSelect

WEnd

Func CreateUser()

$FirstState = GUICtrlRead($Firstname)

$LastState = GUICtrlRead($Lastname)

$OfficeState = GUICtrlRead($Office)

$ExtensionState = GUICtrlRead($Extension)

$TitleState = GUICtrlRead($Title)

$DepartmentState = GUICtrlRead($Department)

If $FirstState = "" Then

Msgbox (0,"First Name","Please enter a First Name")

EndIf

If $LastState = "" Then

MsgBox (0,"Last Name", "Please enter a Last Name")

EndIf

If $TitleState = "" Then

MsgBox (0,"Title", "Please enter the user Title")

EndIf

If $DepartmentState = "" Then

MsgBox (0,"Department", "Please enter user Department")

EndIf

If $ExtensionState = "" Then

MsgBox (0,"Extension", "Please enter the user phone extension")

Endif

If $OfficeState = "London Office" Then

$Phone = "(519) 649-2363"

Endif

If $OfficeState = "Toronto Office" Then

$Phone = "(416) 360-1777"

Else

$Phone = "NA"

Endif

RunWait (@ComSpec & " /C dsadd user " & """CN="& $Firststate & "." & $LastState & ",OU=FXUsers,DC=corp,DC=filogix,DC=com"""& " -fn " & $FirstState & " -ln " & '"' & $LastState & '"' & " -display " & '"' & $FirstState & " " & $Laststate & '"' & " -office " & '"' & $Officestate & '"'& " -tel " & '"' & $Phone & '"' & "-ext " & $ExtensionState & '"' & " -title " & '"' & $TitleState & '"' & " -dept " & '"' & $DepartmentState & '"'& " -company " & """Filogix Limited Partnership""" & " -email " & $FirstState & "." & $LastState & "@filogix.com" & " -upn " & $FirstState & "." & $LastState & "@filogix.com" & " -pwd ABCD+1234 -loscr login.bat -mustchpwd yes -disabled no")

EndFunc

Func Clear()

GuIctrlsetdata (3,"")

GuIctrlsetdata (5,"")

GuIctrlsetdata (9,"")

GuIctrlsetdata (11,"")

GuIctrlsetdata (13,"")

EndFunc

Share this post


Link to post
Share on other sites

Any help is MUCH appreciated. I will look at those tools also posted.

Share this post


Link to post
Share on other sites

@swalsh19

This should get you going.

You will have to put in your details and add this to you script.

Const $olDistributionListItem = 7

$Set $objOutlook = ObjCreate("Outlook.Application")
$Set $objList = $objOutlook.CreateItem($olDistributionListItem )

$objList.DLName = $OfficeState ; This your variable from your script !!
$objList.Save

; Change it to the proper details
$bjGroup = ObjGet("LDAP://CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

For $strUser in $objGroup.Member
    $objUser = ObjGet("LDAP://" & $strUser)
    $strUserName = $objUser.displayName

    $objRecipient = $objOutlook.Session.CreateRecipient($strUserName)
    $objRecipient.Resolve
    $objList.AddMember ($objRecipient)
Next

Play around with this to see what it does

Regards,

ptrex

Share this post


Link to post
Share on other sites

Thanks for this I appreciate it. I'm very NEW to all this and was taking the code a previous employee used and editing it. I will play with the snipet you gave me, but if you have a chance can you maybe put some comments beside the areas I need to edit to match my AD config?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Is only the one line needed to be changed from:

$bjGroup = ObjGet("LDAP://CN=Finance Users,OU=Finance,,DC=fabrikam,DC=com")

TO this:

$bjGroup = ObjGet("LDAP://"""CN="& $Firststate & "." & $LastState & ",OU=FXUsers,DC=corp,DC=filogix,DC=com"""")

Is that syntax for that line correct? Just a little unclear as to where I would be putting in the name of the distribution group I want added for all users....

I also am getting a compile error with the original code I posted when I try to compile it.

Edited by swalsh19

Share this post


Link to post
Share on other sites

I think my syntax is wrong for that line above. Mind you when I try to compile I get an error before that line anyways so I'm not sure...

Share this post


Link to post
Share on other sites

I appreciate the info ptrex has given me. Can anyone see what it is I have wrong on the line above>

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

ANyone see what I'm doing wrong? For some reason the original code that currently is working as I'm using the application won't even compile. AM I missing something in my system>

Edited by swalsh19

Share this post


Link to post
Share on other sites

I use a message box to test code... try this

it is not correct

MsgBox(0x0, "", "LDAP://"""CN="& $Firststate & "." & $LastState & ",OU=FXUsers,DC=corp,DC=filogix,DC=com"""")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0