In one scenario, there was a need for me to get all mailbox related information using WMI and C#.Net.

Here is a code snippet to get all mailbox information from an Exchange Server - WMI & C#.Net.

using System;
using System.Management;

namespace ConsoleTwo
{
    class Class1
    {


        [STAThread]
        static void Main(string[] args)
        {
            try
            {
 
                System.Management.ConnectionOptions objcon = new System.Management.ConnectionOptions();
                 objcon.Impersonation = ImpersonationLevel.Impersonate;
 
                // Exchange Server Name
                string cServername = "Server Name";
 
                // Create a management scope into Exchange WMI namespace
                System.Management.ManagementScope exScope =
                    new System.Management.ManagementScope(@"\\" + cServername + @"\root\MicrosoftExchangeV2", objcon);

                // Create a query to get the data from the Exchange WMI
                System.Management.ObjectQuery objQry =
                    new System.Management.ObjectQuery("SELECT * FROM Exchange_Mailbox");

                // Retrieves a collection of management objects based on the query.
                System.Management.ManagementObjectSearcher objSrch =
                    new System.Management.ManagementObjectSearcher(exScope, objQry);
                System.Management.ManagementObjectCollection qryCol = objSrch.Get();

                 // Loop each item in the collection
                foreach (System.Management.ManagementObject mailBox in qryCol)
                {
                     Console.WriteLine("{0} {1} {2}", mailBox["MailboxDisplayName"].ToString() , mailBox["TotalItems"].ToString() , mailBox["size"].ToString() );
                 }
             }
            catch (Exception eVal)
            {
                Console.Write(eVal.InnerException + eVal.Message + eVal.Source + eVal.StackTrace );
            }
            Console.Read(); 
        }
    }
    }