0

我曾经使用 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 server 2016 获得未读电子邮件的数量(在我迁移了我的 Exchange 之后)。

4

1 回答 1

0

此库不适用于 Exchange 2016,编写此库的人Glen Scales建议以下解决方案:

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

并获取最新的 EWS 托管 API(从 gi​​t hub 编译) https://github.com/gscales/Powershell-Scripts/blob/master/Microsoft.Exchange.WebServices.zip 将 dll 放在与脚本相同的目录中。

然后运行

导入模块 .\unReadModule2016.ps1

(这将导入模块 cmdlet)

并使用

获取-UnReadCountOnFolder -MailboxName user@mailbox.com

于 2019-12-04T11:41:21.560 回答