Hello,
Thank you for specifying. We updated the script accordingly. Find it below. In the script, we added the $recipientTypeDetails variable that specifies types of mailboxes that should be included into the report. The variable should be set to an array of corresponding Recipient Type Details property values. For example, 1 references a User mailbox. For details about the property values, have a look at the following post on Microsoft forums: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_exchon-mso_o365b/recipient-type-values/7c2620e5-9870-48ba-b5c2-7772c739c651.
$sendAsColumnID = "{dd288413-e52e-496f-b419-fb77012d2259}" # TODO: modify me
$sendOnBehalfOfColumnID = "{b8393021-85d0-45e0-bde4-6ec2fe4d8f79}" # TODO: modify me
$fullAccessColumnID = "{3176bc12-9853-4add-982f-212728ecd0e6}" # TODO: modify me
$recipientTypeDetails = @(1, 4) # TODO: modify me
# Search filter
$filter = "(&(sAMAccountType=805306368)(|"
foreach ($type in $recipientTypeDetails)
{
$filter += "(msExchRecipientTypeDetails=$type)"
}
$filter += "))"
$Context.DirectorySearcher.AppendFilter($filter)
try
{
# Execute search
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$sendAsObjectNames = New-Object System.Collections.ArrayList
$sendOnBehalfOfObjectNames = New-Object System.Collections.ArrayList
$fullAccessObjectNames = New-Object System.Collections.ArrayList
# Get users that have permissions to user mailbox
$object = $Context.BindToObjectBySearchResultEx($searchResult, $True)
try
{
$mailboxParams = $object.GetMailParameters()
}
catch
{
continue
}
# Get Send As trustees
for ($i = 0; $i -lt $mailboxParams.SendAs.Count; $i++)
{
$trustee = $mailboxParams.SendAs.GetItem($i, [ref]"ADS_PROPERTY_NONE")
if ([System.String]::IsNullOrEmpty($trustee.ObjectSid) -or [Softerra.Adaxes.Utils.WellKnownSecurityPrincipalInfo]::IsWellKnown($trustee.ObjectSid))
{
continue
}
if ($NULL -eq $trustee.SearchResult)
{
continue
}
$trusteeName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($trustee.SearchResult.AdsPath, "None")
$sendAsObjectNames.Add($trusteeName)
}
# Get Send on Behalf Of
for ($i = 0; $i -lt $mailboxParams.GrantSendOnBehalfTo.Count; $i++)
{
$object = $mailboxParams.GrantSendOnBehalfTo.GetItem($i, [ref]"ADS_PROPERTY_NONE")
if ($NULL -eq $object.SearchResult)
{
continue
}
$objectName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($object.SearchResult.AdsPath, "None")
$sendOnBehalfOfObjectNames.Add($objectName)
}
# Get Full Access trustees
if ($NULL -ne $mailboxParams.MailboxRights)
{
$mailboxPermissions = $mailboxParams.MailboxRights.GetPermissions()
foreach ($mailboxPermission in $mailboxPermissions)
{
if (!($mailboxPermission.AllowedRights -band [Softerra.Adaxes.Interop.Adsi.Exchange.ADM_EXCHANGE_MAILBOX_RIGHTS_ENUM]::ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS) -or
$mailboxPermission.InheritedAllowedRights -band [Softerra.Adaxes.Interop.Adsi.Exchange.ADM_EXCHANGE_MAILBOX_RIGHTS_ENUM]::ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS)
{
continue
}
$trustee = $mailboxPermission.Trustee
if (!([System.String]::IsNullOrEmpty($trustee.ObjectSid)) -and
[Softerra.Adaxes.Utils.WellKnownSecurityPrincipalInfo]::IsWellKnown($trustee.ObjectSid))
{
continue
}
if ($NULL -eq $trustee.SearchResult)
{
continue
}
$trusteeName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($trustee.SearchResult.AdsPath, "None")
$fullAccessObjectNames.Add($trusteeName)
}
}
$customColumns = @{
$sendAsColumnID = [System.String]::Join(", ", $sendAsObjectNames.ToArray());
$sendOnBehalfOfColumnID = [System.String]::Join(", ", $sendOnBehalfOfObjectNames.ToArray());
$fullAccessColumnID = [System.String]::Join(", ", $fullAccessObjectNames.ToArray());
}
$Context.Items.Add($searchResult, $customColumns, $NULL)
}
}
finally
{
# Close the remote session and release resources
if ($searchIterator) { $searchIterator.Dispose() }
}