计算未读电子邮件以换取每个用户

时间:2010-05-04 17:02:17

标签: c# exchange-server

我想用c#来计算未读电子邮件的数量 我都连接到交换机,并获得所有用户和相应的电子邮件。

我的连接..

    RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
                PSSnapInException snapInException = null;
                PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
                Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
                myRunSpace.Open();

                Pipeline pipeline = myRunSpace.CreatePipeline();
                Command myCommand = new Command("Get-Mailbox");

                pipeline.Commands.Add(myCommand);

                Collection<PSObject> commandResults = pipeline.Invoke();

                // Ok, now we've got a bunch of mailboxes, cycle through them
                foreach (PSObject mailbox in commandResults)
                {
                    //define which properties to get
                    foreach (String propName in new string[] { "Name", "EmailAddresses", "Database", "OrganizationalUnit", "UserPrincipalName" })
                    {
                        //grab the specified property of this mailbox
                        Object objValue = mailbox.Properties[propName].Value;
.......

1 个答案:

答案 0 :(得分:1)

您想要的命令是Get-MailboxStatistics。您可以从返回的对象中获取Inbox_Number_Unread。

Glen Scales发布了this blog article关于通过PowerShell提取类似信息的信息。它应该指向正确的方向。它有一个完整的脚本,可以收集所有邮箱的有用属性。