Steven Meier Posted January 19, 2007 Share Posted January 19, 2007 This Active directory UDF was created by another member of these forums who I have asked for help but has not replied. It should create an exchange mailbox . I have written and app that passes input to the Active directory APP called DSADD that creates a USer in Active directory fine but would like to use the UDF below to create a mailbox also. I have not been able to get it to work and am unsure where I am going worng could someone have a look and help me get this working correctly. CODE; UserCreateMailbox ; $user - User to add mailbox to ; $mdbstore - Mailbox storename ; $store - Information store ; $server - Email server ; $admingroup - Administrative group in Exchange ; $domain - Domain name Func UserCreateMailbox($user, $mdbstore, $store, $server, $admingroup, $domain) If ObjectExists($user) = 0 Then Return 0 Dim $objConnection, $objRootDSE $objConnection = ObjCreate("ADODB.Connection") ; Create COM object to AD $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") ; Open connection to AD $objRootDSE = ObjGet("LDAP://RootDSE") Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name $strQuery = "<LDAP://" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree" $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists $ldap_entry = $objRecordSet.fields (0).value $oUser = ObjGet($ldap_entry) ; Retrieve the COM Object for the object If $oUser.HomeMDB <> "" Then Return 0 $mailboxpath = "LDAP://CN=" $mailboxpath = $mailboxpath & $mdbstore $mailboxpath = $mailboxpath & ",CN=" $mailboxpath = $mailboxpath & $store $mailboxpath = $mailboxpath & ",CN=InformationStore" $mailboxpath = $mailboxpath & ",CN=" $mailboxpath = $mailboxpath & $server $mailboxpath = $mailboxpath & ",CN=Servers,CN=" $mailboxpath = $mailboxpath & $admingroup $mailboxpath = $mailboxpath & ",CN=Administrative Groups,CN=State Street,CN=Microsoft Exchange,CN=Services,CN=Configuration," $mailboxpath = $mailboxpath & $domain $oUser.CreateMailbox ($mailboxpath) $oUser.SetInfo Return 1 EndFunc ;==>UserCreateMailbox Link to comment Share on other sites More sharing options...
Steven Meier Posted January 19, 2007 Author Share Posted January 19, 2007 Just to add , there seem to be mistakes in the code ....I have tried to undertsnad it but am not very good at ldap. Cheers Link to comment Share on other sites More sharing options...
fry2k Posted May 23, 2007 Share Posted May 23, 2007 hey, i have the same problem. how does it works? thx for any help. i just want to create a exchange 2003 mail account (user exists). thx Link to comment Share on other sites More sharing options...
ptrex Posted May 23, 2007 Share Posted May 23, 2007 @all Maybe this can help you out. expandcollapse popup; ------ SCRIPT CONFIGURATION ------ $strDCName = "<DC>" ; e.g. "batman" $strUserName = "CN=<userCN>" ; e.g. "Random User" ; ------ END CONFIGURATION ------ ; get the default and config NC names $oIADS = ObjGet("LDAP://RootDSE") $strDefaultNC = $oIADS.Get("defaultnamingcontext") $strConfigNC = $oIADS.Get("configurationNamingContext") $strContainer= "/CN=Users," & $strDefaultNC $objContainer = ObjGet("LDAP://" & $strDCName & $strContainer) ; find the target user $oIADSUser = ObjGet("LDAP://" & $strUserName & ",CN=Users," & $strDefaultNC) $oMailBox = $oIADSUser ; Open the Connection. $oConnection = ObjCreate("ADODB.Connection") $oCommand = ObjCreate("ADODB.Command") $oRecordSet = ObjCreate("ADODB.Recordset") $oConnection.Provider = "ADsDSOObject" $oConnection.Open ("ADs Provider") ; Build the query to find the private MDBs. Use the first one if any are found. $strQuery = "<LDAP://" & $strConfigNC & ">;(objectCategory=msExchPrivateMDB);name,adspath;subtree" $oCommand.ActiveConnection = $oConnection $oCommand.CommandText = $strQuery $oRecordSet = $oCommand.Execute If Not $oRecordSet.EOF Then $oRecordSet.MoveFirst() $firstMDB = String($oRecordSet.Fields("ADsPath").Value) Else $firstMDB = "" EndIf ; create the mailbox $oMailBox.CreateMailbox ($firstMDB) $oIADSUser.SetInfo() ConsoleWrite ("Created mailbox for " & $strUserName) Enjoy !! Regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
fry2k Posted May 24, 2007 Share Posted May 24, 2007 thx for the anser. But i dont understand the working. Can you give me an example? example domain: put.local username: test i have made chages @ $strDCName = "dc=put,dc=local" ; e.g. "batman" $strUserName = "CN=test" ; e.g. "Random User" but i geht the error C:\Dokumente und Einstellungen\Administrator\Desktop\excha.au3 (39) : ==> Variable must be of type "Object".: $oMailBox.CreateMailbox ($firstMDB) $oMailBox^ ERROR thx for any help! Link to comment Share on other sites More sharing options...
lordofthestrings Posted May 25, 2007 Share Posted May 25, 2007 well the errormessage explains where your problem lies.. you perform an action on a variable that is not possible: $oMailBox = let's say at the moment an integer or a string text, not a connection to an object, then you try to launch a method that should be exposed through your connection to the object. you can see this yourself if you put a messagebox in front of the errorring rule. $oIADSUser = ObjGet("LDAP://" & $strUserName & ",CN=Users," & $strDefaultNC) $oMailBox = $oIADSUser this code is not too good practise.. I would write : $oMailBox = ObjGet("LDAP://" & $strUserName & ",CN=Users," & $strDefaultNC) if NOT isobj($oMailBox) then exit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now