Solved

Check the Mailbox size of a remote user via C#

Posted on 2007-03-20
12
2,005 Views
Last Modified: 2012-08-13
At my company we have over 5000 mailboxes. We currently have a older VBScript that runs on a daily basis that logs onto each mailbox, checks the total size of the mailbox, compares it to a hardcoded "limit" then sends the user an e-mail if they are getting close to full letting them know our companies mailbox policies and how to get help. I know Exchange 2003 (native) that we have has a capability similar to this, but you are unable to edit the message that they recieve so we can not use it... Exchange's message specifically tells people to use PST files which are against company policy. This program takes roughly 4-6 hours a day to run... its rather slow.

I've been tasked with updating this program... currently it will not run in a WindowsXP environment is is running on a legacy Windows2000 box.

I have been searching for quite some time and could not find an answer. Is there a way, useing C# which is my company standard, for me to get the current mailbox size of a user? I can easily pull their limits using DirectoryServices, but I just cant break into getting their current size.

I can not install anything on our Exchange servers themselves, nor can I modify any Exchange DLL's to modify their message. We have a Exchange 2003 native environment with about 6 servers.
0
Comment
Question by:ALogvin
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 10

Expert Comment

by:MATTHEW_L
ID: 18756307
I'm not a C# programmer at all so I can't help you there.

However, it is a shame that you cannot make 1 .dll modification.  Changing the native warning message actually isn't very difficult.  You could then run all of this straight through Exchange with no external applications or code.

Here is the article in case you are interested.  This .dll would have to be copied to each Exchange server, but would work nicley.  I have used this method in the past.

http://www.exchangeserver2003.com/articles/showarticle.asp?id=1148632910
0
 
LVL 11

Author Comment

by:ALogvin
ID: 18756391
It is a matter of support. If we change 1 little DLL, Microsoft will just blame every little flaw in Exchange on that. We pay a lot for our support contract with MS to have them just dump the problem because we modified their stuff. God forbid they not hard-code in things like this.
0
 
LVL 10

Expert Comment

by:MATTHEW_L
ID: 18756476
I agree 100%.

Good luck in your search.
0
 
LVL 10

Expert Comment

by:MATTHEW_L
ID: 18756732
0
 
LVL 11

Author Comment

by:ALogvin
ID: 18756789
Yah, I've read that one a few times. All VBS, nothing in .NET at all. I cant run this on an Exchange server either, due to the reasons stated above.
0
 
LVL 10

Expert Comment

by:MATTHEW_L
ID: 18757525
What about at the bottom, seemed like something in C#
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Author Comment

by:ALogvin
ID: 18757796
Nope. WebDav = VBScript, Visual Basic, Visual C.  There is a link for ADO, but ADO has to be run on the Exchange Server, and there are no C# methods, only C++ and VBS.
0
 
LVL 3

Accepted Solution

by:
sppence earned 500 total points
ID: 18775208
you can do it using the system.management namespace.  

Here's a sample (replace SERVERNAME with the name of your Exchange server - watch for line wrap...) - obviously, add your own code to the foreach to do something with the values once you get them.

            UInt64 mailboxsize;
            string storagegroupname;
            string storename;
            string mailboxdisplayname;

            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher();
            searcher.Scope = new System.Management.ManagementScope("\\\\SERVERNAME\\root\\MicrosoftExchangeV2");
            searcher.Query = new System.Management.ObjectQuery("Select * From Exchange_Mailbox");
            System.Management.ManagementObjectCollection results = searcher.Get();
            foreach (System.Management.ManagementObject mailbox in results)
            {
               mailboxsize = Convert.ToUInt64(mailbox.Properties["Size"].Value);
               storagegroupname = mailbox.Properties["StorageGroupName"].Value.ToString();
               storename = mailbox.Properties["StoreName"].Value.ToString();
               mailboxdisplayname = mailbox.Properties["MailboxDisplayName"].Value.ToString();
            }




FYI, I've included a few of the properties availabe on a mailbox here, but there's over a dozen properties on the WMI object - you can see a complete list using WBEMTEST or I believe you can use the GetText method of the "mailbox" object above to show the full MOF text with all the properties and their values.

hope this helps.
0
 
LVL 3

Expert Comment

by:sppence
ID: 18775368
I forgot to mention above - you don't have to run this from the Exchange server, but the user you run this as does have to have rights to read that information from WMI (an account that is an admin on your Exchange server should work).
0
 
LVL 11

Author Comment

by:ALogvin
ID: 18796142
I'm trying it now, and will let you know...
0
 
LVL 11

Author Comment

by:ALogvin
ID: 18802151
That looks like it will work. I have a test domain that I am a full admin in, and it worked great there. It wont work in my production domain, but the only difference is my rights, so im sure once i get that resolved it will work great there too.

Thanks!!!
0
 

Expert Comment

by:NSDCT
ID: 25573960
Is there a way that this can be done for a specific mailbox on the exchange server? The code appears to be searching the entire exchange server and I only want to check a specific mailbox. I'm also getting permission denied which I am hoping would go away if it was specific to the box that I care about (I do have permission to that). The credentials on the email box are not he same as the admin account on the server that this would run on so I may also need to be able to pass a specific username and passoword. Is this possible? Please let me know.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
This video discusses moving either the default database or any database to a new volume.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now