Script repository
The script generates a report that includes linked mailboxes and their master accounts. To execute the script, create a report with corresponding custom column. The report scope should be set to an OU or container where linked mailboxes are located.
Parameters
$masterAccountNameColumndID- the identifier of the custom column that will store the master account for report items. The column has to be of the Directory object type. To get the column identifier:- In the Report-specific columns section, on the Columns tab, right-click the custom column.
- In the context menu, navigate to Copy and click Column ID.
- The column identifier will be copied to clipboard.
$noMasterAccountGroupName- the text that will be present in the custom column if a linked mailbox has no master account.
$masterAccountNameColumndID = "{cf958507-8f26-4e77-9072-a6b828a6f956}" # TODO: modify me
$noMasterAccountGroupName = "No master account" # TODO: modify me
$criteria = New-AdmCriteria "user" -Expression {msExchRecipientTypeDetails -eq 2}
$Context.DirectorySearcher.AddCriteria($criteria)
$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
You must be signed in to comment.