Forum Discussion
Libbo88
Apr 18, 2024Copper Contributor
obtain an “Unread E-mail Report” for individual email addresses filtered by specific company name.
HI All,
i have created PS for exchange to genarate above requerment.but when i run this i get CSV without any data in it.can anyone tell me what is the problem.
my script is
$inboxStats = Get-MailboxFolderStatistics -Identity $targetEmailAddress -FolderScope Inbox
$unreadCount = $inboxStats.UnreadItemCount
# Connect to Exchange Online (Microsoft 365)
Install-Module ExchangeOnlineManagement
Connect-ExchangeOnline
# Specify the target email address (replace with the desired user's email)
$targetEmailAddress = "Globale ADMIN account @ domain.com"
# Specify the organization domain (replace with the desired domain)
$organizationDomain = "SENDING COMPANY Domain"
# Get the unread item count in the Inbox folder for the specified user
$inboxStats = Get-MailboxFolderStatistics -Identity $targetEmailAddress -FolderScope Inbox
$unreadCount = $inboxStats.UnreadItemCount
# Create a custom object with mailbox details
$mailboxInfo = [PSCustomObject]@{
DisplayName = (Get-Mailbox $targetEmailAddress).DisplayName
EmailAddress = $targetEmailAddress
UnreadCount = $unreadCount
}
# Export the results to a CSV file
$mailboxInfo | Export-Csv -Path "Sharepath\UnreadEmailReport.csv" -NoTypeInformation
# Display a message
Write-Host "Unread email report exported to UnreadEmailReport.csv"
# Get unread emails from the specified organization
$unreadFromOrg = Get-MailboxFolderStatistics -Identity $targetEmailAddress -FolderScope Inbox | Where-Object { $_.UnreadItemCount -gt 0 -and $_.FolderPath -like "*$organizationDomain*" }
# Display the unread emails from the organization
Write-Host "Unread emails from $organizationDomain:"
$unreadFromOrg | ForEach-Object {
Write-Host "- Subject: $($_.Name), Unread Count: $($_.UnreadItemCount)"
}
- There is no way to get this data by default via Exchange PowerShell only, which is why I suppose the workaround of moving messages from said company/domain was implemented.
You can look into a solution based on the Graph SDK for PowerShell instead, here's a sample to get you started: https://practical365.com/mailbox-contents-report/
4 Replies
Sort By
- That script will only work if items received from the company in question are all stored within a subfolder of Inbox, named as the company domain.
- Libbo88Copper ContributorVasilMichev.
thank you for your reply.can you explain/what to edit how can i get report, which is in inbox by specific company domain?- There is no way to get this data by default via Exchange PowerShell only, which is why I suppose the workaround of moving messages from said company/domain was implemented.
You can look into a solution based on the Graph SDK for PowerShell instead, here's a sample to get you started: https://practical365.com/mailbox-contents-report/