Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


script to create users whit mailboxes

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,47123
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> script to create users whit mailboxes
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 script to create users whit mailboxes - 5/15/2007 10:53:38 PM   
  shayt

 

Posts: 25
Score: 0
Joined: 1/28/2007
Status: offline
hello all

i have a script that need to create 50 users whit mailboxes

' ------ SCRIPT CONFIGURATION ------
intNumUsers = 50         ' Number of users to create
strParentDN = "OU=Test,DC=Dc,DC=com" ' DN of where the users will be created
strHomeMDB = "CN=Mailbox Store 1(DCN1),CN=First Storage Group,CN=InformationStore,CN=Dc1," &_
            "CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=mycom," &_
            "CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=ogosync,DC=com" 
' ------ END CONFIGURATION ---------
' Taken from ADS_USER_FLAG_ENUM
Const ADS_UF_NORMAL_ACCOUNT = 512

set objParent = GetObject("LDAP://" & strParentDN)

for i = 1 To intNumUsers
  strUser = "test" & i
  strPwd = "Test1234"
  Set objUser = objParent.Create("user", "cn=" & strUser)
  objUser.Put "sAMAccountName", strUser
  objUser.SetInfo
  objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
  objUser.SetPassword(strPwd)
  objUser.AccountDisabled=False
  objUser.SetInfo
  WScript.Echo "Created " & strUser
  objUser.CreateMailBox strHomeMDB
  objUser.SetInfo()
  Wscript.Echo "Successfully mailbox-enabled user."
Next
WScript.Echo ""
WScript.Echo "Created " & intNumUsers & " users"

when i run it i get this error :

script : c:\test
Line: 61
Char: 4
Error : There is no such object on the server

Facility: LDAP Provider
ID no: 80072030
microsoft CDO for exchange Management

Code: 80072030
Source: (null)

unfortunately i can't find what is wrong whit the script
can you please help me...?

thanks in advance
 
 
Post #: 1
 
 RE: script to create users whit mailboxes - 5/15/2007 11:25:30 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
first of all the script you posted is only 29 lines long so it would be a bit difficult to see whats wrong on line 61.
second of all there are a lot of scripts out there for creating Users and there mailboxes

(in reply to shayt)
 
 
Post #: 2
 
 RE: script to create users whit mailboxes - 5/16/2007 12:59:28 AM   
  shayt

 

Posts: 25
Score: 0
Joined: 1/28/2007
Status: offline
the error is comeing from this line :

"objUser.CreateMailBox strHomeMDB"

can you recommend me on another script like this one?


(in reply to gdewrance)
 
 
Post #: 3
 
 RE: script to create users whit mailboxes - 5/16/2007 1:16:24 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
We have had this discussion before. So I see this is still the same problem
http://www.visualbasicscript.com/m_44548/mpage_1/key_strHomeMDB/tm.htm#45465

(in reply to shayt)
 
 
Post #: 4
 
 RE: script to create users whit mailboxes - 5/16/2007 1:36:43 AM   
  shayt

 

Posts: 25
Score: 0
Joined: 1/28/2007
Status: offline
yes i remember ...
but now i past all the CN problem
but is still get an error ...:(
on this part " objUser.CreateMailBox strHomeMDB "
the user (only the first one) is created but after that i'm geting the error....

(in reply to gdewrance)
 
 
Post #: 5
 
 RE: script to create users whit mailboxes - 5/16/2007 1:42:44 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
so are you reading names from an excel file, how are the accounts being made

(in reply to shayt)
 
 
Post #: 6
 
 RE: script to create users whit mailboxes - 5/16/2007 6:14:02 AM   
  shayt

 

Posts: 25
Score: 0
Joined: 1/28/2007
Status: offline
not from any file... :(
i guess this is the part i missed....
can you help whit that?

(in reply to gdewrance)
 
 
Post #: 7
 
 RE: script to create users whit mailboxes - 5/16/2007 5:28:39 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
On closer inspection I see the Users are being made in the script.
have you tried just creating the users. I cant test it so see if it works.
And you do know that the User Accounts will be e.g. test, test1, test2 etc due to strUser = "test" & i

intNumUsers = 50         ' Number of users to create
strParentDN = "OU=Test,DC=Dc,DC=com" 'Check that this is Correct in AD on your server
strHomeMDB = "CN=Mailbox Store 1(DCN1),CN=First Storage Group,CN=InformationStore,CN=Dc1," &_  'Remove this for now
            "CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=mycom," &_
            "CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=ogosync,DC=com" 

' ------ END CONFIGURATION ---------
' Taken from ADS_USER_FLAG_ENUM
Const ADS_UF_NORMAL_ACCOUNT = 512 'This enables the account 514 Disables it

set objParent = GetObject("LDAP://" & strParentDN)

for i = 1 To intNumUsers
  strUser = "test" & i
  strPwd = "Test1234"
  Set objUser = objParent.Create("user", "cn=" & strUser)
  objUser.Put "sAMAccountName", strUser
  objUser.SetInfo
  objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
  objUser.SetPassword(strPwd)
  objUser.AccountDisabled=False
  objUser.SetInfo
  WScript.Echo "Created " & strUser
next
WScript.Echo ""
WScript.Echo "Created " & intNumUsers & " users"

(in reply to shayt)
 
 
Post #: 8
 
 RE: script to create users whit mailboxes - 5/16/2007 8:10:47 PM   
  shayt

 

Posts: 25
Score: 0
Joined: 1/28/2007
Status: offline
i'm geting an error that "objUser.SetInfo" dosen't exist...

i have find an other script that take the data from a CSV file
here is the script :
Option Explicit   ' Forces declaration of variables - always use this
Dim sIOLocation
Dim sCSVFile
Dim sLogFile
Dim oInputConnection
Dim oInputRecordSet
Dim oLogObject
Dim oLogOutput
Dim oNewUser
' Variables needed for LDAP connection
Dim oRootLDAP
Dim oContainer
' Holding variables
Dim sLogon
Dim sFirstName
Dim sLastName
Dim sDisplayName
Dim sPassword
Dim nPwdLastSet
Dim nUserAccountControl ' Used to enable the account
Dim sLDAPdomain
Dim sLDAPExchangeServer ' See instructions before running script
Dim sLDAPmail   ' Will be set to sLogon + "@" + sLDAPdomain
Dim sLDAPmailnickname ' Will be set to sLogon
Dim sLDAPhomeMDB  ' See instructions before running script
Dim sLDAPmDBUseDefaults ' Will be set to true
' Set the full path to the Exchange server
' Broken up into separate sections for readability
' If you have multiple Exchange servers, consider including the
'      Exchange server name in your CSV file
' See accompanying instructions for quickly determining this field
'      your organization
sLDAPExchangeServer = "/o=First Organization"
sLDAPExchangeServer = sLDAPExchangeServer & "/ou=First Administrative Group"
sLDAPExchangeServer = sLDAPExchangeServer & "/cn=Configuration/cn=Servers"
sLDAPExchangeServer = sLDAPExchangeServer & "/cn=W2K3-STD"
' Set the Exchange homeMDB variable
' Broken up into separate sections for readability
' If you have multiple Exchange stores, consider including the
'      store name in your CSV file
' See accompanying instructions for quickly determining this field
'      your organization
sLDAPhomeMDB = "CN=Mailbox Store (W2K3-STD),"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=First Storage Group,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=InformationStore,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=W2K3-STD,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=Servers,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=First Administrative Group,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=Administrative Groups,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=First Organization,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=Microsoft Exchange,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=Services,"
sLDAPhomeMDB = sLDAPhomeMDB & "CN=Configuration,"
sLDAPhomeMDB = sLDAPhomeMDB & "DC=example,DC=com"
' Modify this to match your company's AD domain
sLDAPdomain="example.com"
' Location of CSV file and to which log files will be written
sIOLocation = "C:\Scripts\" 'KEEP TRAILING SLASH!
' Full path to input file
sCSVFile = sIOLocation&"example.csv"
sLogFile = sIOLocation&"IO.log"
' This value is set to true
' Indicates that the user account will use default mail store rules
sLDAPmDBUseDefaults = TRUE
' Commands used to open the CSV file and select all of the records
set oInputConnection = createobject("adodb.connection")
set oInputRecordSet = createobject("adodb.recordset")
oInputConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & _
   sIOLocation & ";Extended Properties=""text;HDR=NO;FMT=Delimited"""
oInputRecordSet.open "SELECT * FROM " & sCSVFile,oInputConnection
' Open the log file for writing
set oLogObject = CreateObject("Scripting.FileSystemObject")
set oLogOutput = oLogObject.CreateTextFile(sLogFile)
oLogOutput.WriteLine Now & ": Log started"
' Create a connection to the Active Directory Users container.
Set oRootLDAP = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://cn=Users," & _
   oRootLDAP.Get("defaultNamingContext"))
' Allows processing to continue even if an error occurs (i.e. dup user)
' We put this below the CSV  and AD information since processing can
' continue with a single bad record, but not if there is a problem with
' the CSV file or AD connection
on error resume next
do until oInputRecordSet.EOF ' Reads the values (cells) in the sInputFile file.
err.clear      ' Reset the error counter
' --------- Start creating user account
' Read variable information from the CSV file
' and build everything needed to create the account
sLogon = oInputRecordSet.Fields.Item(0).value
sFirstName = oInputRecordSet.Fields.Item(1).value
sLastName = oInputRecordSet.Fields.Item(2).value
sDisplayName = sLastName&", "&sFirstName
sPassword = oInputRecordSet.Fields.Item(3).value
' Build the User account
Set oNewUser = oContainer.Create("User","cn="&sFirstName&" "&sLastName)
oNewUser.put "sAMAccountName",lcase(sLogon)
oNewUser.put "givenName",sFirstName
oNewUser.put "sn",sLastName
oNewUser.put "UserPrincipalName",lcase(SLogon)&"@"&sLDAPdomain
oNewUser.put "DisplayName",sDisplayName
oNewUser.put "name",lcase(sLogon)
' Write this information into Active Directory so we can
' modify the password and enable the user account
oNewUser.SetInfo
'If it was successful, continue processing
If err.number = 0 Then
oLogOutput.WriteLine Now & ": " & sLogon & ": Successfully created user account"
' Change the users password and turn off requirement to change at next login
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", 0
' Enable the user account
oNewUser.Put "userAccountControl", 512
oNewUser.SetInfo
' If the password set and account enable was successful, indicate. Otherwise, write diagnostics.
If err.number = "0" Then
   oLogOutput.WriteLine Now & ": " & sLogon & ": Successfully created user password and enabled account"
Else
   oLogOutput.WriteLine Now & ": " & sLogon & ": Password or account enable error : " & err.number & err.description
End If
' Build and write the users Exchange attributes
oNewUser.put "mDBUseDefaults", sLDAPmDBUseDefaults
oNewUser.put "mail", lcase(SLogon)&"@"&sLDAPdomain
oNewUser.put "msExchHomeServerName", sLDAPExchangeServer
oNewUser.put "mailnickname", lcase(sLogon)
oNewUser.put "homeMDB", sLDAPhomeMDB
oNewUser.SetInfo 
' If the Exchange attributes were successful, indicate.  Otherwise, write diagnostics.
If err.number = "0" Then
   oLogOutput.WriteLine Now & ": " & sLogon & ": Successfully created user's Exchange attributes"
Else
   oLogOutput.WriteLine Now & ": " & sLogon & ": Exchange attributes error : " & err.number & err.description
End If
Else
oLogOutput.WriteLine Now & ": " & sLogon & ": Error creating account: " & err.number & err.description
End If
' --------- End of user account creation
' Move ahead to the next record
oInputRecordSet.movenext
Loop
' Close the log file
oLogOutput.WriteLine Now & ": Input ended"
oLogOutput.Close

this script is runing too but i'm gteing an error on the log file and nothing happen
the error i get is : "Error creating account: 424Object required"

10x gdewrance for all your help

(in reply to gdewrance)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> script to create users whit mailboxes Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts