Exchange 2016未读电子邮件

时间:2019-11-28 16:05:38

标签: powershell exchange-server exchange-server-2016

我曾经使用EWSUtil库从Exchange Server2010下方的链接获取多个用户的未读电子邮件。

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

代码:

[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
}

但是现在(在完成Exchange迁移之后),我无法使用Exchange Server 2016来获取未读电子邮件计数。

1 个答案:

答案 0 :(得分:0)

此库无法与Exchange 2016一起使用,编写此库的人Glen Scales建议采用以下解决方案:

使用此脚本: https://github.com/gscales/Powershell-Scripts/blob/master/unReadModule2016.ps1

,还可以获取最新的EWS托管API(从git hub编译) https://github.com/gscales/Powershell-Scripts/blob/master/Microsoft.Exchange.WebServices.zip 将dll与脚本放在同一目录中。

然后运行

导入模块。\ unReadModule2016.ps1

(这将导入模块cmdlet)

并使用

Get-UnReadCountOnFolder -MailboxName user@mailbox.com