Jump to content

Automating the addition of Exchange Distribution Groups


 Share

Recommended Posts

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

Link to comment
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

Link to comment
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

Link to comment
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?

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...