简体   繁体   中英

Count the unread emails in exchange for each user

i want to count the unread emails in exchange with c# i all conected to the exchange, and get all users and the corresponding email.

for the connection i have ..

    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;
.......

The command you want is Get-MailboxStatistics . You can get the Inbox_Number_Unread off the objects returned.

Glen Scales posted this blog article about pulling similar information via PowerShell. It should point you in the right direction. It has a full script which gathers useful properties off all mailboxes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM