Solved

Check the Mailbox size of a remote user via C#

Posted on 2007-03-20
12
2,031 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add group policy for windows 10 users 3 32
VB.NET 2008 - SQL Timeout 9 24
Additional DC vs Child Domain 12 21
exchange, activesync 2 7
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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