SAIDI Belkacem
SAIDI Belkacem

Reputation: 348

Unread Emails for Exchange 2016

I used to get unread emails for multiple users using the EWSUtil library from the link bellow with Exchange server2010.

https://gsexdev.blogspot.com/2008/11/find-unused-mailbox-powershell-gui.html

Code:

[void][Reflection.Assembly]::LoadFile("C:\EWSUtil.dll")

$mails=( "user0", "user1", "user2")
ForEach ($mail in $mails)
{
$mbcombCollection = @()

$specificuser = get-mailbox $mail

    $mbcomb = "" | select DisplayName,EmailAddress, Unread
    $mbcomb.DisplayName = $specificuser.DisplayName.ToString()
    $mbcomb.EmailAddress = $specificuser.WindowsEmailAddress.ToString()
    $mbMailboxEmail = $specificuser.WindowsEmailAddress.ToString()

    $ewc = new-object EWSUtil.EWSConnection($mbMailboxEmail,$false, $null,$null,$null,$null)
    $dTypeFld = new-object EWSUtil.EWS.DistinguishedFolderIdType
    $dTypeFld.Id = [EWSUtil.EWS.DistinguishedFolderIdNameType]::inbox

    $mbMailbox = new-object EWSUtil.EWS.EmailAddressType
    $mbMailbox.EmailAddress = $mbMailboxEmail
    $dTypeFld.Mailbox = $mbMailbox

    $fldarry = new-object EWSUtil.EWS.BaseFolderIdType[] 1
    $fldarry[0] = $dTypeFld

    $fldList = $ewc.GetFolder($fldarry)
    [EWSUtil.EWS.FolderType]$pfld = [EWSUtil.EWS.FolderType]$fldList[0];
        $mbcomb.Unread = $pfld.UnreadCount
    $mbcombCollection += $mbcomb
$mbcombCollection
Add-Content C:\UnreadEmailCheck1.txt $mbcombCollection
}

But now I can't get the unread emails count with Exchange server 2016 (after I did the migration of my Exchange).

Upvotes: 0

Views: 2615

Answers (1)

SAIDI Belkacem
SAIDI Belkacem

Reputation: 348

This library is not working with Exchange 2016, the person who wrote this library Glen Scales suggested the following solution:

Use this script: https://github.com/gscales/Powershell-Scripts/blob/master/unReadModule2016.ps1

and also grab the latest EWS Managed API (compiled from git hub) https://github.com/gscales/Powershell-Scripts/blob/master/Microsoft.Exchange.WebServices.zip put the dll in the same directory as the script.

Then run

Import-Module .\unReadModule2016.ps1

(this will import the module cmdlets)

and use

Get-UnReadCountOnFolder -MailboxName [email protected]

Upvotes: 0

Related Questions