Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to create mailboxes in Exchange 5.5 2

Status
Not open for further replies.

richardv

MIS
Oct 5, 2002
22
0
0
Is it possible to create mailboxes in Exchange 5.5?

I'm hoping to automatically create mailboxes for users when I create their accounts using a script...
 
What environment are you running in..?
straight NT 4.0/Exch. 5.5 ?
Mixed W2k/Exh 5.5 ?

In a Mixed environ, I have found it best to use a 2 phase system:
1) Script the user accoutn creation
2) Use the Exch 5.5 Import Utility for MB's.

Bill
[noevil]
 
Havent got an example to hand but read a book on ADSI recently and if i am not mistaken Exchange is based on LDAP and i seem to recall seeing some scripts on it in the book. if you like i can have a look over the weekend and get back to you if you like?
rich
 

I am willing to purchase any book that will help me get started.

My goal:
use arguments to define important fields such as alias, Display Name, distribution list, NT account, etc. so that I can integrate it into my current adduser script.

My environment:
NT 4.0 as PDC /w Exchange 5.5
NT 4.0 as BDC
Win2K for everything else
 
I have two scripts from a book called managing enterprise systems with the WSH - one script does Exchange 5.5 see below: all thanks go to the author Stein Borge - ISBN number 1-893115-67-4

'createmailbox.vbs
Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = 2
Const ADS_RIGHT_EXCH_MAIL_SEND_AS = 8
Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = 16
Const ADS_SID_WINNT_PATH = 5
Const ADS_SID_HEXSTRING = 1
Dim objMailbox, objContainer, strServer
Dim strAlias, strMTA, strMDB, strSMTPAddr, strDisplayName
Dim objSid, strSidHex, strComputer, strSite, strOrg
Dim objComputer, strUserID, strDomain
Dim objSec, objSD, objDACL, objAce
strServer = "Odin"
strSite = "Office"
strDomain = "Acme"
strDisplayName = "Fred Smith"
strSMTPAddr = "FredSmith@acme.com"
strAlias = "Freds"
strUserID = "Freds"

Set objComputer = GetObject("LDAP://" & strServer)
'get the organization
strOrg = objComputer.o
'get the recipients container for the site
Set objContainer = _
GetObject("LDAP://" & strServer & "/CN=Recipients,OU=" _
& strSite & ",o=" & strOrg)

'get the SID for the account to be associated with the new mailbox
Set objSid = CreateObject("ADsSID")
objSid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & strDomain & "/" & strUserID
strSidHex = objSid.GetAs(ADS_SID_HEXSTRING)

'create a new MailBox
Set objMailbox = objContainer.create("organizationalPerson", "cn=" & strAlias)
'set display name and alias
objMailbox.Put "mailPreferenceOption", 0
objMailbox.Put "cn", strDisplayName
objMailbox.Put "uid", strAlias
objMailbox.Put "Home-MTA", _
"cn=Microsoft MTA,cn=" & strServer & ",cn=Servers,cn=Configuration,ou=" _
& strSite & ",o=" & strOrg

objMailbox.Put "Home-MDB", _
"cn=Microsoft Private MDB,cn=" & strServer & _
",cn=Servers,cn=Configuration,ou=" _
& strSite & ",o=" & strOrg
objMailbox.Put "MAPI-Recipient", True
'objMailbox.Put "rfc822Mailbox", strSMTPAddr
objMailbox.rfc822Mailbox = strSMTPAddr

objMailbox.Put "textEncodedORaddress", _
"c=US;a= ;p=" & strSite & ";o=" & strOrg & ";s=" & strAlias

objMailbox.textEncodedORaddress = _
"c=US;a= ;p=" & strSite & ";o=" & strOrg & ";s=" & strAlias
objMailbox.Put "Assoc-NT-Account", strSidHex
objMailbox.SetInfo
'create security objects
Set objSec = CreateObject("ADsSecurity")
Set objAce = CreateObject("AccessControlEntry")

Set objSD = objSec.GetSecurityDescriptor("LDAP://" & strServer & _
"/CN=Recipients,OU=" & strSite & ",o=" & strOrg)
Set objDACL = objSD.DiscretionaryAcl
objAce.Trustee = strDomain & "\" & strUserID
objAce.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or _
ADS_RIGHT_EXCH_MAIL_SEND_AS Or _
ADS_RIGHT_EXCH_MAIL_RECEIVE_AS
objAce.AceType = ADS_ACETYPE_ACCESS_ALLOWED
objDACL.AddAce objAce
objSD.DiscretionaryAcl = objDACL
objSec.SetSecurityDescriptor objSD Regards
Steve Friday
 
I think you just made my year.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top