DESCRIPTION
This script forces Policy "Controls selection of mailbox stores where Exchange mailbox creation is allowed." to create a mailbox according to the Active Roles-specific policy settings, when a user object is created outside of Active Roles, e.g. within Active Directory Users and Computers.
Copy the following script to a handler script box, point a policy to this policy script, set the scope and check the boxes "Handle changes from the DirSync control" in the properties of the script execution connection.
Make sure to apply an Active Roles-specific Mailbox provisioning policy to the same scope as for this policy.
Note This code may use functions from the Active Roles Script Policy Best Practices. Please, follow the link to obtain instructions and code for those functions.
SCRIPT
'*********************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
'*********************************************************************************
Option Explicit
Sub onPostCreate(Request)
'--- Check the addressed object class, in this case "user". It could be any object class, just name it
'--- Optimization: process only user objects
If (LCase(Request.Class) "user") Then Exit Sub
'--- Check for modifications, made in AD, which are then synchronized to Active Roles
'--- Optimization: process only modifications, received from DC by DirSync
If (Request.Parameter("RequestSource") = EDST_MOD_SOURCE_CLIENT) Then Exit Sub
If (Request.Parameter("RequestSource") = EDST_MOD_SOURCE_DB) Then Exit Sub
'--- Check if a object already have any mailbox and mailNickNAme
Dim strHomeMDB, strmailNickname, strsAMAccountName
DirObj.GetInfoEx Array("homeMDB", "mailNickname", "sAMAccountName"), 0
On Error Resume Next
strHomeMDB = DirObj.Get("homeMDB")
On Error GoTo 0
On Error Resume Next
strsAMAccountName = DirObj.Get("sAMAccountName")
On Error GoTo 0
If (Not IsEmpty(strHomeMDB)) Then Exit Sub
'--- React on these changes, e.g. Set the following attribute to the value "true",
'--- to force the mailbox creation routine in Active Roles to create a mailbox.
'--- The following attribute change forces Active Roles to create a mailbox, if there is a mailbox provisioning rule set on the OU
'--- So, configure an Email-Alias and mailbox provisioning policy first!
DirObj.Put "mailNickname", strsAMAccountName
DirObj.Put "edsaCreateMsExchMailbox", "true"
DirObj.SetInfo
End Sub
'***** END OF CODE ***************************************************************