我曾经使用 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 之后)。