Requin | Un exemple de script pour créer une boite Exchange, à adapter à tes besoins. Voial qui devrait te donner une idée de comment utiliser ADSI.
Author: Leszek Winiarski Description: Create exchange mailbox with all user permissions (ny-security-descriptor) Script:
Code :
- Set sid = CreateObject("ADsSID" )
- Set sec = CreateObject("ADsSecurity" )
- Set ace = CreateObject("AccessControlEntry" )
- Const ADS_SID_HEXSTRING = 1
- Const ADS_SID_WINNT_PATH = 5
- Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = &H2
- Const ADS_RIGHT_EXCH_MAIL_SEND_AS = &H8
- Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = &H10
- ' -HERE YOU MUST CHANGE THE NAMES-
- server = "EXCHANGE_SERVER_NAME"
- Org = "ORGANISATION_NAME"
- Site = "SITE_NAME"
- domain = "DOMAIN_NAME_OF_NT_ACCOUNT"
- '--- MailBox Parameters --
- strDisplayName = "Demo Account"
- strFirstName = "Demo"
- strLastName = "Account"
- strAlias = "demoacc"
- strMTA = "cn=Microsoft MTA,cn=" & server &
- ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
- strMDB = "cn=Microsoft Private MDB,cn=" & server &
- ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
- strSMTPAddr = "demoacc@company.com"
- '--- Build Recipient container's adsPath that looks like this:
- LDAP://myserver/CN=Recipients, OU=Site, O=Org
- ADsPath = "LDAP://" + server
- ADsPath = ADsPath + "/cn=Recipients,OU="
- ADsPath = ADsPath + Site
- ADsPath = ADsPath + ",O="
- ADsPath = ADsPath + Org
- Set objCont = GetObject(ADsPath)
- 'Create a new MailBox
- Set mailBox = objCont.Create("organizationalPerson", "cn=" & strAlias)
- mailBox.Put "mailPreferenceOption", 0
- mailBox.Put "givenName", strFirstName
- mailBox.Put "sn", strLastName
- mailBox.Put "cn", strDisplayName
- mailBox.Put "uid", strAlias
- mailBox.Put "Home-MTA", strMTA
- mailBox.Put "Home-MDB", strMDB
- mailBox.Put "mail", strSMTPAddr
- mailBox.Put "MAPI-Recipient", True
- mailBox.Put "rfc822Mailbox", strSMTPAddr
- '--------------
- ' ASSOCIATING TO NT PRIMARY ACCOUNT
- ' (REQUIRED ADSI TOOL KIT - REGSVR32 ADSSECURITY.DLL )
- '---------------
- sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" &
- & "/" & strAlias & ",user"
- sidHex = sid.GetAs(ADS_SID_HEXSTRING)
- mailBox.Put "Assoc-NT-Account", sidHex
- ' Commit the property cache to the directory service
- mailBox.SetInfo
- '-------------
- '--- SET THE MAIL BOX SECURITY ------
- '-- To allow the user to modify user attribute, send mail and receive mail
- '-------------
- Set sd = sec.GetSecurityDescriptor(mailBox.ADsPath)
- Set dacl = sd.DiscretionaryAcl
- ace.Trustee = domain & "\" & strAlias
- ace.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or
- ADS_RIGHT_EXCH_MAIL_SEND_AS Or ADS_RIGHT_EXCH_MAIL_RECEIVE_AS
- ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
- dacl.AddAce ace
- sd.DiscretionaryAcl = dacl
- sec.SetSecurityDescriptor sd
- *************
|
|