Hi,
The built in report for forwarded users does not return any results for our environment, likely because we mainly use Exchange Online. I am attempting to generate my own report but struggling to get results. I have added a custom column that will list the user who is receiving the mail via forwarding. I have the following currently:
# Set search criteria
$criteria = New-AdmCriteria @(
"adm-LinkedMailbox",
"adm-PublicFolderMailbox"
)
$criteria.AddType("user", {mailboxType -eq "any"})
$Context.DirectorySearcher.AddCriteria($criteria)
# Custom column identifiers
$forwardedUser = "{4a7d1b39-bfb6-4935-a3e8-a36aaf57294d}"
# Build the report
try
{
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$user = $Context.BindToObjectBySearchResult($searchResult)
try {
# Get forward to
$mailboxParams = $user.GetMailParameters()
$deliveryOptions = $mailboxParams.MailFlowSettings.DeliveryOptions
$forwardToDN = $deliveryOptions.ForwardingAddress.DistinguishedName
#Bind to user
if ($forwardToDN) {
$forwardedRecipient = $context.BindToObjectByDN($forwardToDN)
$columnValues = @{
$forwardedUser = $forwardedRecipient
}
$Context.Items.Add($user, $columnValues, $NULL)
}
} catch {
Continue
}
}
}
finally
{
if ($searchIterator) { $searchIterator.Dispose() }
}
Could you please point me in the direction of where I am going wrong?
Thanks,
Gareth