We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Linked mailboxes and their master accounts

October 22, 2021 Views: 965

The script generates a report that includes licked mailboxes and their master accounts. To execute the script, create a report with the corresponding custom column. The report scope should be set to an OU or container where linked mailboxes are located.

Parameters:

  • $masterAccountNameColumndID - Specifies the identifier of the custom column that will store the master account for report items. The column has to be of Active Directory object type. it can be used to group linked mailboxes and their master accounts together. To get the column identifier:
    1. In the Report-specific columns section, on the Columns tab, right-click the custom column.
    2. In the context menu, navigate to Copy and click Column ID.
    3. The column identifier will be copied to clipboard.
  • $noMasterAccountGroupName - Specifies the text that will be present in the custom column if a linked mailbox has no master account.
Edit Remove
PowerShell
$masterAccountNameColumndID = "{cf958507-8f26-4e77-9072-a6b828a6f956}" # TODO: modify me
$noMasterAccountGroupName = "No master account" # TODO: modify me

$Context.DirectorySearcher.AppendFilter("(&(sAMAccountType=805306368)(msExchRecipientTypeDetails=2))")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("msExchMasterAccountSid")
try
{
    $searchIterator = $Context.DirectorySearcher.ExecuteSearch()
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        
        # Get Master Account
        $sidBytes = $searchResult.GetPropertyByName("msExchMasterAccountSid").Values[0]
        $msExchMasterAccountSid = New-Object "Softerra.Adaxes.Adsi.Sid" @($sidBytes, 0)
        
        
        try
        {
            $masterAccount = $Context.BindToObject("Adaxes://<SID=$msExchMasterAccountSid>")
        }
        catch
        {
            $Context.Items.Add($searchResult, @{ $masterAccountNameColumndID = $noMasterAccountGroupName }, $NULL)
            continue
        }
        
        $masterAccountDN = $masterAccount.Get("distinguishedName")
        $Context.Items.Add($searchResult, @{ $masterAccountNameColumndID = $masterAccountDN }, $NULL)
        $Context.Items.Add($masterAccount, @{ $masterAccountNameColumndID = $masterAccountDN }, $NULL)
    }
}
finally
{
    # Release resources
	if ($searchIterator) { $searchIterator.Dispose() }
}


Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers