Hello,
The minimum information necessary to re-connect a disconnected mailbox are the GUID of the disconnected mailbox and the Distinguished Name (DN) of the Exchange mailbox store where the mailbox resides. Usually, this information is stored in the properties of a user account, but when a mailbox is disconnected, Exchange removes these properties from the user account. To be able to successfully reconnect the database on re-provisioning, we recommend you to save this information in certain properties of the user whose mailbox is being disconnected. To do this, you need to add an action to the Custom Command that you use for user deprovisioning that will save this information once a user is deprovisioned.
To store a mailbox GUID and a mailbox store DN, you can use Adaxes virtual attributes. Such attributes are not stored in Active Directory, but you may use them the same as any other properties of directory objects. For mailbox GUIDs you'll need an attribute that can store binary values, for example, CustomAttributeBinary1, for mailbox stores you'll need a string attribute, for example, CustomAttributeText1.
Then, you can add an action to the Business Rule that performs re-provisioning. The action will run a PowerShell script that will search for a disconnected mailbox with a GUID and located in a mailbox store that are specified in the virtual attributes. If such a mailbox is found, the action will reconnect it. If it is not found (the mailbox has already been deleted by Exchange) or if a GUID and a mailbox store are not specified in the virtual attributes, it will create a new mailbox.
To implement such a solution:
I. Add an action that saves the mailbox GUID and mailbox store DN in virtual attributes
To add an action that will save the mailbox GUID and mailbox store DN in virtual attributes to your Custom Command that you use for deprovisioning:
-
Launch Adaxes Administration Console.
-
In the Console Tree, expand the service node that represents your Adaxes service.
-
Navigate to and select the Custom Command that you use to deprovision users.
-
Select the set of actions and conditions, in which the user's mailbox gets disconnected.
-
Click the Add Action button.
-
Select the Run a program or PowerShell script action and paste the following script:
$mbGUIDProperty = "adm-CustomAttributeBinary1" # TODO: modify me
$mbStorePathProperty = "adm-CustomAttributeText1" # TODO: modify me
# Get mailbox guid and mailbox store dn
$exchangeGuid = $Context.TargetObject.Get("msExchMailboxGuid")
$mailboxStoreDN = $Context.TargetObject.Get("homeMDB")
# Save exchange guid and database dn in custom attribute
$Context.TargetObject.Put($mbGUIDProperty, $exchangeGuid)
$Context.TargetObject.Put($mbStorePathProperty, $mailboxStoreDN)
$Context.TargetObject.SetInfo()
-
In the script:
- $mbGUIDProperty - specifies the virtual attribute that will be used to store the mailbox GUID,
- $mbStorePathProperty - specifies the virtual attribute that will be used to store the mailbox store DN.
Modify them, if necessary.
-
When done, click OK.
-
Now you need to put the action before the mailbox is disconnected, otherwise the necessary properties will be deleted by Exchange before Adaxes can save them. For this purpose use the Move Up button located at the bottom of the list of actions and conditions.
-
When done, click Save changes.
I. Add an action that recoonects a disconnected mailbox
To add an action that will reconnect a mailbox:
-
In the Console Tree, navigate to and select the Business Rule that re-provisions users.
-
Select a set of actions and conditions and click the Add Action button or click the Add action to a new set link if you want to create a new action/condition set.
-
Select the Run a program or PowerShell script action and paste the following script:
$exchangeServer = "exchangeserver.domain.com" # TODO: Modify me
$alias = "%username%" # TODO: modify me
$mbGUIDProperty = "adm-CustomAttributeBinary1" # TODO: modify me
$mbStorePathProperty = "adm-CustomAttributeText1" # TODO: modify me
function CreateMailbox($alias)
{
# Select an Exchange mailbox store for the user based on Property Patterns
$propertyPatternDNs = $Context.TargetObject.GetEx("adm-EffectivePropertyPatterns")
foreach ($propertyPatternDN in $propertyPatternDNs)
{
# Bind to property patern
$propertyPattern = $Context.BindToObjectByDN($propertyPatternDN)
# Search an item for the Exchange mailbox store
foreach ($item in $propertyPattern.Items)
{
if ($item.PropertyName -ine "homeMDB")
{
continue
}
# Get the mailbox store
$mailboxStorageDatabase = $item.GetNextMailboxStorageDatabase($Context.TargetObject)
# Create a mailbox
$Context.TargetObject.CreateMailbox($alias, $mailboxStorageDatabase.AdsPath)
# Notify that the mailbox store has been used
$item.NotifyMailBoxStorageDataBaseIsUsed($Context.TargetObject, $mailboxStorageDatabase)
# Exit the function
return
}
}
}
# Get mailbox GUID and Exchange mailbox store DN from virtual properties
try
{
$mailboxGuidByte = $Context.TargetObject.Get($mbGUIDProperty)
$mailboxStoreDN = $Context.TargetObject.Get($mbStorePathProperty)
}
catch
{
# No saved information about a disconnected mailbox, a new mailbox will be created
CreateMailbox $alias
return
}
# Create a remote PowerShell session to the Exchange Server
$session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
Import-PSSession -session $session
# Search the user's disconnected mailbox
$mailboxGuid = New-Object "System.Guid" (,$mailboxGuidByte)
$disconnectMailbox = Get-MailboxStatistics -Database $mailboxStoreDN | Where {$_.DisconnectDate -ne $Null -and $_.Identity -eq $mailboxGuid}
# If the disconnected mailbox was not found, create a new one
if($disconnectMailbox -eq $NULL)
{
CreateMailbox $alias
return
}
# Reconnect the mailbox
Connect-Mailbox -Identity $mailboxGuid -Database $mailboxStoreDN -User "%distinguishedName%"
# Exit remove session, free up resources
Remove-PSSession -Session $session
-
In the script:
- $mbGUIDProperty - specifies the virtual attribute that will be used to store the mailbox GUID,
- $mbStorePathProperty - specifies the virtual attribute that will be used to store the mailbox store DN,
- $exchangeServer - specifies the fully qualified domain name (FQDN) of your Exchange Server,
- $alias - specifies a template for generate a user's Exchange Alias (in case a new mailbox needs to be created).
Modify them, if necessary.
-
When done, click OK, then click Save changes.