Jump to content

ADSI and/or VBS use for creating objects in Autoit


Recommended Posts

Folks,

I have posted a few queries here over the week , I have managed to nut everything bar my last task.

Using ADSI I believe to create the mailbox.

I will post my working code for app here... I have created the LDAP string but unsure where to go from here.

The asterisks are for client confidentiality, but feel free to use if wish.

I am not much of a scripter so if my code is untidy, I am happy to hear about it, but it does work, so I am happy.

CODE
#include <GUIConstants.au3>

Func _RunDOS($sCommand)

Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)

EndFunc ;==>_RunDOS

$mainwindow = GUICreate("**************** User Application", 400, 460)

GUICtrlCreateLabel("USER DETAILS", 15, 8)

GuiCtrlCreateLabel(" **************************** v1.0 16/1/2007", 10, 440)

$App1 = GUICtrlCreateButton("Create User ", 80, 380, 100)

$App2 = GUICtrlCreateButton("Modify User ", 180, 380, 100)

GuiCtrlCreateLabel(" First Name", 30, 25)

$FirstN = GUICtrlCreateInput ( " " , 85, 23, 90, 20, )

GuiCtrlCreateLabel(" Last Name", 180, 25)

$LastN = GUICtrlCreateInput ( "" , 240, 23, 100, 20, )

GuiCtrlCreateLabel("Description : " , 30, 49)

$DES = GUICtrlCreateInput ( "" , 85, 48, 150, 20 )

GuiCtrlCreateLabel("Office : " , 245, 52)

$OFF = GUICtrlCreateCombo ("" , 275, 48, 100, 20 )

GUICtrlSetData(-1, "Christchurch|Westport|Spring Creek|Rapahoe|Ngakawa|Ohai|Reefton|Rotowaro|East Mine|Stockton|Natures Flame" , "Christchurch")

GuiCtrlCreateLabel("Email : " , 30, 75)

$Email = GUICtrlCreateInput ( "" , 85, 70, 280, 20 )

GuiCtrlCreateLabel("Logon Name : " , 30, 95)

$LogonN = GUICtrlCreateInput ( "" , 95, 92, 100, 20 )

GuiCtrlCreateLabel("Password : " , 197, 95)

$Passw = GUICtrlCreateInput ( "" , 250, 92, 100, 20 )

GuiCtrlCreateLabel("Users OU " , 30, 120)

$UserOU = GUICtrlCreateCombo ("", 85,115, 100)

GUICtrlSetData(-1,"SE_Users|SERF_Users","SE_USERS")

GuiCtrlCreateLabel("Local File and Print Server for User files: " , 30, 140)

$FP = GUICtrlCreateCombo ("", 220, 138, 100, 20 )

GUICtrlSetData(-1,"CHCHFP01|ROTOFP01|EASTFP01|OHAIFP01|STCKFP01|WESTFP01|RAPAFP01|NGAKFP01|SPRGFP01|REEFFP01|SERFA

DFP01" , "CHCHFP01")

GuiCtrlCreateLabel("MailBox Store Name : " , 30, 180)

$MB = GUICtrlCreateCombo ( "" , 135, 178, 240, 20 )

GUICtrlSetData(-1,"Mailbox Store (Christchurch Users)|Mailbox Store (North Island Users)|Mailbox Store (West Coast - Southland Users)" , "Mailbox Store (Christchurch Users)")

GUISetState()

$dummywindow = GUICreate("Dummy window for testing ", 200, 100)

GUISwitch($mainwindow)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg(1)

Select

Case $msg[0] = $App1

$sPath1 = @SystemDir & "\DSADD user "

$sF = GUICtrlRead($FirstN) ; FirstName

$sL = GUICtrlRead($LastN) ;LastName

$sD = GUICtrlRead($DES) ;Description

$sO = GUICtrlRead($OFF) ;Office

$sE = GUICtrlRead($Email) ;Email address

$sLo = GUICtrlRead($LogonN) ;Logon Name

$sPass = GUICtrlRead($Passw) ;Password

$sUserOU = GUICtrlRead($UserOU) ;OU users will be placed into

$sHD = "H:" ; Letter for home drive

$sLog = "login.bat" ; Login script Name

$sFP = GUICtrlRead($FP) ;Local file and print Server

$sHMD = "\\"& $sFP & "\" & $sLo & "$" ;Home drive in profile tab setting

$OU = '"CN='& $sF & ' ' & $sL & ',OU=' & $sUserOU & ',DC=se,DC=***********,DC=co,DC=nz"' ; user to create

$sDis = '"'& $sF & ' '& $sL &'"' ;display name

$sUPN = $sLo & "@se.**********.co.nz"

$Wdrive = "\\"& $sFP & "\d$\data\Users"

$MBStore = GUICtrlRead($MB)

If $sF And $sL And $sD And $sO And $sE And $sLo And $sPass And $sUserOU And $sFP Then

MsgBox ( 1 , 'OUTPUT FOR USER CREATION ' , 'User:= ' & $sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog )

;RunWait($sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog)

DriveMapDel("W:")

DriveMapAdd( "W:", ""& $Wdrive & "")

DirCreate( "W:\" & $sLo & "" )

DirCreate( "W:\" & $sLo & "\data" )

DriveMapDel("W:")

;Creates Mail box below for user

$s_strServer = "CHCHEX01"

$s_strExchangeOrg = "*************"

$s_strDomain = "DC=se,DC=**********,DC=co,DC=nz"

;' These are the defaults, compare with your server and amend.

$s_strAdminGroup = "Christchurch"

$s_strStorageGroup = "First Storage Group"

$s_strStoreName = $MBStore

$s_strMailbox= "cn="& $sLo &"," ; User name for mailbox

;' Build LDAP $s_string

$s_strMailbox = $s_strMailbox & "CN=" & $s_strStoreName

$s_strMailbox = $s_strMailbox & ",CN=" & $s_strStorageGroup

$s_strMailbox = $s_strMailbox & ",CN=InformationStore"

$s_strMailbox = $s_strMailbox & ",CN=" & $s_strServer

$s_strMailbox = $s_strMailbox & ",CN=Servers"

$s_strMailbox = $s_strMailbox & ",CN=" & $s_strAdminGroup

$s_strMailbox = $s_strMailbox & ",CN=Administrative Groups"

$s_strMailbox = $s_strMailbox & ",CN=" & $s_strExchangeOrg

$s_strMailbox = $s_strMailbox & ",CN=Microsoft Exchange"

$s_strMailbox = $s_strMailbox & ",CN=Services"

$s_strMailbox = $s_strMailbox & ",CN=Configuration"

$s_strMailbox = $s_strMailbox & "," & $s_strDomain

MsgBox(0,"EMAIL String for user mailbox creation","$s_strMailbox="&$s_strMailbox)

;

; <================Mail creation code would go here.

;

Else

MsgBox(48, "User Creation Error", "You must provide all required information.")

EndIf

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg[0] = $App2

$sPath1 = @SystemDir & "\DSMOD user "

$sF = GUICtrlRead($FirstN) ; FirstName

$sL = GUICtrlRead($LastN) ;LastName

$sD = GUICtrlRead($DES) ;Description

$sO = GUICtrlRead($OFF) ;Office

$sE = GUICtrlRead($Email) ;Email address

$sLo = GUICtrlRead($LogonN) ;Logon Name

$sPass = GUICtrlRead($Passw) ;Password

$sUserOU = GUICtrlRead($UserOU) ;OU users will be placed into

$sHD = "H:" ; Letter for home drive

$sLog = "login.bat" ; Login script Name

$sFP = GUICtrlRead($FP) ;Local file and print Server

$sHMD = "\\"& $sFP & "\" & $sLo & "$" ;Home drive in profile tab setting

$OU = '"CN='& $sF & ' ' & $sL & ',OU=' & $sUserOU & ',DC=se,DC=************,DC=co,DC=nz"' ; user to create

$sDis = '"'& $sF & ' '& $sL &'"' ;display name

$sUPN = $sLo & "@se.***********.co.nz"

$Wdrive = "\\"& $sFP & "\d$\data\Users"

If $sF And $sL And $sUserOU Then

MsgBox ( 1 , 'OUTPUT FOR USER CREATION ' , 'User:= ' & $sPath1 & ' ' & $OU & ' -samid ' & $sLo & ' -upn ' & $sUPN & ' -fn ' & $sF & ' -ln ' & $sL & ' -display ' & $sDis & ' -pwd ' & $sPass & ' -desc ' & $sD & ' -office ' & $sO & ' -email ' & $sE & ' -hmdir ' & $sHMD & ' -hmdrv ' & $sHD & ' -loscr ' & $sLog )

Else

MsgBox(48, "User Modicfication Error", "You must provide First Name, Last Name , Users OU")

EndIf

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow

ExitLoop

EndSelect

WEnd

The code below is an example of ADSI mailbox creation but I am lost as to how to convert to autoit.

I am happy with what I have so far, as it creates the complete script line (if you run app you will see the msg box produce the output line )

Any help with this last task would help greatly as I feel once I see how it works I will be fine.

CODE
Sub ADSICreateMailBoxEnabledUser _

(MDBName,StorageGroup,Server,AdminGroup,Organization,DomainName,emailname,FirstName,LastName)

'split the domain name to get the directory name for it

DomainDN = "dc=" & Replace(DomainName,".",",dc=")

recip = "CN=" & emailname

' get the container

Set objContainer = GetObject("LDAP://CN=users," & DomainDN)

' create a recipient

Set objUser = objContainer.Create("User", recip)

objUser.Put "samAccountName", emailname

objUser.Put "sn", LastName

objUser.Put "givenName", FirstName

objUser.Put "userPrincipalName", emailname

objUser.SetInfo

objUser.SetPassword "123456"

objUser.AccountDisabled = False

Set objMailbox = objUser

objMailbox.CreateMailbox "LDAP://CN=" & MDBName & _

",CN=" & StorageGroup & _

",CN=InformationStore" & _

",CN=" & Server & _

",CN=Servers" & _

",CN=" & AdminGroup & _

",CN=Administrative Groups" & _

",CN=" & Organization & _

",CN=Microsoft Exchange,CN=Services" & _

",CN=Configuration," & DomainDN

objUser.SetInfo

End Sub

Link to comment
Share on other sites

@Steven Meier

this would give you a good start

Func ADSICreateMailBoxEnabledUser _($MDBName,$StorageGroup,$Server,$AdminGroup,$Organization,$DomainName,$emailname,$FirstName,$LastName)

;split the domain name to get the directory name for it
$DomainDN = "dc=" & StringReplace($DomainName,".",",dc=")

$recip = "CN=" & $emailname

; get the container
 $objContainer = ObjGet("LDAP://CN=users," & $DomainDN)

; create a recipient
 $objUser = $objContainer.Create("User", $recip)
$objUser.Put ("samAccountName", $emailname)
$objUser.Put ("sn", $LastName)
$objUser.Put ("givenName", $FirstName)
$objUser.Put ("userPrincipalName", $emailname)

$objUser.SetInfo()
$objUser.SetPassword ("123456" )
$objUser.AccountDisabled = 0

 $objMailbox = $objUser

$objMailbox.CreateMailbox ("LDAP://CN=" & $MDBName & _)
",CN=" & $StorageGroup & _
",CN=InformationStore" & _
",CN=" & $Server & _
",CN=Servers" & _
",CN=" & $AdminGroup & _
",CN=Administrative Groups" & _
",CN=" & $Organization & _
",CN=Microsoft Exchange,CN=Services" & _
",CN=Configuration," & $DomainDN

$objUser.SetInfo()

EndFunc

regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@

All parameters of the function need to have values specified, otherwise it will give errors !!

ADSICreateMailBoxEnabledUser($MDBName,$StorageGroup,$Server,$AdminGroup,$Organization,$DomainName,$emailname,$FirstName,$LastName)

When calling the function you need to set values for all these varialbles.

I didn't write the script I only translated it for you from VBS to AU3.

regards,

ptrex

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...