November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)
Exchange (3) blog.crowe.co.nz.Models.Category

Exchange

Reinstalling IIS on an Exchange 2000 or Exchange 2003 server

If you are running IIS on an Exchange Server 2000 or 2003 machine make sure you really think hard before you uninstall IIS - it is not a trivial process to get your exchange and IIS linked together again.

Microsoft has a KB article #320202 available here http://support.microsoft.com/default.aspx?scid=kb;en-us;320202 that describes the process in detail to get the system working again.

Apparently when you remove IIS you have also removed some additional configuration parameters that exchange has added to the IIS Metabase and you must follow the 6 steps below to relink the attributes when you install IIS again.

  • Back Up Data
  • Dismount the Mailbox and the Public Information Store
  • Stop Exchange Services and Remove IIS
  • Reinstall Internet Information Service and Reapply Service Packs
  • Reinstall Exchange Server
  • Restore the Original Exchange Information Store

So this is a non trivial action - just make sure you really know what you are doing prior to removing IIS and if you are going to remove IIS and follow the KB Article give yourself plenty of time...


Windows/Exchange - Email Forwarding System

EFS is "mail relay" software. It was specifically designed to give people with "part time" (dialup) connections to the Internet (or those with fulltime connections but their Internet Service Provider (ISP) does not support ETRN - which is not a protocol I recommend anyway) a way of retrieving mail from their ISP and delivering messages to an internal mail server, such as Microsoft Exchange Server, Lotus Notes 4 or 5, the freeware EMWAC IMS or in fact any RFC compliant SMTP server. You do not need a fulltime connection to the Internet to run EFS - it works with both static (full time) and dynamic (part time) IP addresses.

The best part about EFS is that once it's setup, it is basically maintenance free. Similar mail retrieval programs usually require you to add a separate mailbox for every user that mail will be distributed for - the simple downside of this, continuous maintainance and double data-entry. EFS does away with this by allowing you to specify the domain that you will be accepting mail for (just as you are required to do for your mail server). It is this "Internal routing" feature that makes EFS unique amongst most other POP3 retrievers, the ability to accept and deliver mail for your domain.

For more details see http://www.chimera.co.nz/


Exchange - Using WMI to list all mailboxes and their sizes from c#

First off this is my 100th post to my blog!

This is a sample of how to talk to MS Exchange to enumerate all of the mailboxes and display them with the total message count and total message size.

It also shows examples of:

  • Creating your own table
  • Using a DataView to sort the table
  • Writing to XML from a dataset
  • Padding Strings
  • Using the System.Management namespace
using System;

namespace Sample1
{
    /// 
    /// Summary description for Class1.
    /// 

    class Class1
    {
        /// 
        /// The main entry point for the application.
        /// 

        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_wmiref_cl_exchange_mailbox.asp

                System.Console.WriteLine("Enumerate mailbox sizes in MS Exchange Server - Chris Crowe");
                System.Console.WriteLine();

                // Create a DataSet (only needed if you want to save to XML )
                System.Data.DataSet ds = new System.Data.DataSet();
                // Create a DataTable to hold our results
                System.Data.DataTable dt = new System.Data.DataTable("Mailboxes");            
                // Add the table to the dataset
                ds.Tables.Add(dt);

                // Create columns for our data
                dt.Columns.Add(new System.Data.DataColumn("Mailbox"typeof(String)));
                dt.Columns.Add(new System.Data.DataColumn("Messages"typeof(Int32)));            
                dt.Columns.Add(new System.Data.DataColumn("Size"typeof(Int32)));            

                // 
                System.Management.ConnectionOptions objconn = new System.Management.ConnectionOptions();
                objconn.Impersonation = System.Management.ImpersonationLevel.Impersonate;
                // Gets or sets a value indicating whether user privileges need to be enabled for the 
                // connection operation. This property should only be used when the operation performed 
                // requires a certain user privilege to be enabled (for example, a machine reboot).
                objconn.EnablePrivileges = true;

                // Exchange Server Name
                string cServername = "*"// YOUR EXCHANGE SERVER NAME

                // Create a management scrope into the Exchange WMI namespace
                System.Management.ManagementScope exmangescope = 
                    new System.Management.ManagementScope(@"\\" + cServername + @"\root\MicrosoftExchangeV2",objconn);
            
                // Create a query to get the data from the Exchange WMI
                System.Management.ObjectQuery objquery = 
                    new System.Management.ObjectQuery("SELECT * FROM Exchange_Mailbox");

                // Retrieves a collection of management objects based on the query.
                System.Management.ManagementObjectSearcher objsearch = 
                    new System.Management.ManagementObjectSearcher(exmangescope,objquery);

                // Invokes the WMI query and returns the resulting collection.
                System.Management.ManagementObjectCollection queryCollection1 = objsearch.Get(); 

                // Loop through each item in the collection
                foreach( System.Management.ManagementObject instmailbox in queryCollection1 ) 
                {
                    // Add a row of data to our table
                    dt.Rows.Add(new object[] { 
                                                 instmailbox["MailboxDisplayName"],    
                                                 instmailbox["TotalItems"], 
                                                 instmailbox["size"] } );
                } 

                // Used to calculate the size of all of the mailboxes and the message count
                int TotalMessages=0;
                Int64 TotalSize=0;

                // Create a DataView to sort the data by Mailbox Size
                System.Data.DataView dv = new System.Data.DataView(dt);
                dv.Sort = "Size desc, Mailbox";

                // Write a heading
                System.Console.WriteLine(string.Format("{0} {1} {2} "
                    "Mailbox".PadRight(55), 
                    "Messages".PadLeft(8), 
                    "Size".PadLeft(13)));
            
                // Write a line of dashes
                System.Console.WriteLine("".PadRight(78'-'));

                // Get an enumerator to enumate the DataView to get the rows from the table (sorted)
                System.Collections.IEnumerator enumerator = dv.GetEnumerator();            
            
                // Loop through each item in the table
                while(enumerator.MoveNext())
                {
                    // Get a row 
                    System.Data.DataRowView row = enumerator.Current as System.Data.DataRowView;

                    // Display the row
                    System.Console.WriteLine(string.Format("{0} {1} {2} Kb"
                        row["Mailbox"].ToString().PadRight(55), 
                        row["Messages"].ToString().PadLeft(8), 
                        row["Size"].ToString().PadLeft(10)));

                    // Add the size and message count to our totals
                    TotalMessages += Convert.ToInt32(row["Messages"]);
                    TotalSize += Convert.ToInt64(row["Size"]);
                }

                // Write a row of dashes
                System.Console.WriteLine("".PadRight(78'-'));

                // Write the totals
                System.Console.WriteLine(string.Format("{0} {1} {2} Kb"
                    "Total".PadRight(55), 
                    TotalMessages.ToString().PadLeft(8), 
                    TotalSize.ToString().PadLeft(10)));

                // Write the XML to a file if we want to
                ds.WriteXml("Mailboxes.xml");        
            }

            // Catch any problems and show a message!
            catch(Exception e)
            {
                System.Console.WriteLine("Error : " + e.Message.ToString());
            }
        }
    }
}
 

This is how it displays its output to the console.

If you write the data to a XML file as the above example does this is how it may appear.

xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Mailboxes>
    <Mailbox>WeeThings</Mailbox>
    <Messages>742</Messages>
    <Size>41596</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>SMTP (SBS2003-{7390D6EA-A466-417D-A461-ADEA24553CB8})</Mailbox>
    <Messages>0</Messages>
    <Size>0</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>worldnet</Mailbox>
    <Messages>11</Messages>
    <Size>51</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Paradise</Mailbox>
    <Messages>25</Messages>
    <Size>80</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>SystemMailbox{7390D6EA-A466-417D-A461-ADEA24553CB8}</Mailbox>
    <Messages>401</Messages>
    <Size>361</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Art</Mailbox>
    <Messages>53</Messages>
    <Size>333</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Chris Crowe [MVP]</Mailbox>
    <Messages>20</Messages>
    <Size>170</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Pam Elston</Mailbox>
    <Messages>1052</Messages>
    <Size>20852</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Stocks</Mailbox>
    <Messages>33</Messages>
    <Size>607</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>stuff</Mailbox>
    <Messages>106</Messages>
    <Size>1716</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>TradeMe</Mailbox>
    <Messages>287</Messages>
    <Size>1846</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>chris crowe</Mailbox>
    <Messages>4201</Messages>
    <Size>239183</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>IISFAQMailBoxes</Mailbox>
    <Messages>338</Messages>
    <Size>878</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>WeeThings_Trademe</Mailbox>
    <Messages>16</Messages>
    <Size>278</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>PamStocks</Mailbox>
    <Messages>94</Messages>
    <Size>160</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Pets</Mailbox>
    <Messages>20</Messages>
    <Size>148</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Chris Crowe</Mailbox>
    <Messages>14416</Messages>
    <Size>221939</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>IISMVP</Mailbox>
    <Messages>15</Messages>
    <Size>638</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>CarryingABitTooMuch</Mailbox>
    <Messages>19</Messages>
    <Size>1056</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>chris_iisfaq</Mailbox>
    <Messages>4944</Messages>
    <Size>48027</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Forums</Mailbox>
    <Messages>2</Messages>
    <Size>4</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Test</Mailbox>
    <Messages>4</Messages>
    <Size>5</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>System Attendant</Mailbox>
    <Messages>0</Messages>
    <Size>0</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>psoriasis</Mailbox>
    <Messages>3</Messages>
    <Size>5</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Holiday</Mailbox>
    <Messages>959</Messages>
    <Size>24704</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Braindump</Mailbox>
    <Messages>14</Messages>
    <Size>121</Size>
  </Mailboxes>
</NewDataSet>