Hello,
Thank you for clarifying. Here is the script for generating the report. For information on how to create reports, see https://www.adaxes.com/tutorials_ActiveDirectoryManagement_CreateReport.htm. In the script:
- $messageDateColumnId – Specifies the identifier of the Date/time custom column that will store the mail delivery date. To get the 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.
- $exchangeServer - specifies the fully qualified domain name or IP address of your Exchange Server.
$messageDateColumnId = "{83354eeb-65f4-4fc8-a9b4-15ef27ea23d1}" # TODO: modify me
$exchangeServer = "exchangeServer.domain.com" # TODO: Modify me
$Context.DirectorySearcher.AppendFilter("(&(objectCategory=group)(mailNickname=*))")
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("mail")
try
{
# Connect to the Exchange Server
$session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
Import-PSSession -session $session -AllowClobber -DisableNameChecking
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$mail = $searchResult.GetPropertyByName("mail").Values[0]
$messageTrackingLog = Get-MessageTrackingLog -Recipients $mail -ResultSize Unlimited | Select-Object sender, timestamp | Sort timestamp -Descending
if ($NULL -eq $messageTrackingLog)
{
$messageDate = $NULL
}
else
{
$messageDate = $messageTrackingLog[0].TimeStamp
}
$Context.Items.Add($searchResult, @{$messageDateColumnId = $messageDate}, $NULL)
}
}
finally
{
if ($searchIterator) { $searchIterator.Dispose() }
if ($session) { Remove-PSSession -Session $session }
}