Sign in to follow this  
Followers 0
swalsh19

AD User Creator Script...

2 posts in this topic

I'm trying to ammend to an existing script we have that was created by a previous employee that will add a new user to existing mail distribution groups.

The user would be added to 2 groups automatically, first on being the same for any user, and the second being determined by the office location.

I had gotten a little help here before but I still cannot get this script to compile to test it. Can I get some help to detemine what I have done wrong.

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

'ADD TO DISTRIBUTION GROUPS

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="& $Firststate & "." & $LastState & ",OU=FXUsers,DC=corp,DC=filogix,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

Share this post


Link to post
Share on other sites



I'm trying to ammend to an existing script we have that was created by a previous employee that will add a new user to existing mail distribution groups.

The user would be added to 2 groups automatically, first on being the same for any user, and the second being determined by the office location.

I had gotten a little help here before but I still cannot get this script to compile to test it. Can I get some help to detemine what I have done wrong.

Did you read the errors from the syntax check when you tried to compile?

1. You didn't post the "#" for your #include.

2. Missing #include <ButtonConstants.au3>

3. You have to delimit comments with a semicolon: "; 'ADD TO DISTRIBUTION GROUPS"

4. There is no "Set" or "$Set" in AutoIt

5. You have a very bizarre set of quotes on this line:

; Change it to the proper details
; $bjGroup = ObjGet("LDAP://"""CN="& $Firststate & "." & $LastState & ",OU=FXUsers,DC=corp,DC=filogix,DC=com"""")
$bjGroup = ObjGet("LDAP://CN = " & $Firststate & " ." & $LastState & ", OU = FXUsers, DC = corp, DC = filogix, DC = com")

All of this was found by just running Syntax Check (Ctrl-F5) in SciTE, which you can do for yourself.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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