Can Powershell insert mailbox size query results into SQL?

Posted on 2011-10-27
Last Modified: 2012-05-12

I have a little status webpage that I use to display a couple of different things.  Sort of like a system monitoring webpage.  I'd like to display the number of items in my journalling mailbox on that webpage.  It would be great if the server-side code (.net) could ask the Exchange 2007 for that info directly, but it sounds very complicated.

The alternative thought was to have a scheduled task run a powershell script that pulls the data and inserts it into a database for my page to read.

What do you think?  If it's the latter idea, how do I do it?

Thanks for the help!

Question by:ddotson
    LVL 37

    Accepted Solution


    You could do it with a scheduled task. You would get the number of items in the mailbox with this command:

    $itemcount = (get-mailboxstatistics <mailbox>).itemcount

    You could then use powershell to inset this into a SQL database. This post explains how to do that:


    Author Comment

    This looks good.  The other item I need it the mailbox size.  I tried $itemcount = (get-mailboxstatistics <mailbox>).totalitemsize, but I got this

    [PS] C:\Windows\system32>(get-mailboxstatistics -identity <mailbox>).totalitemsize
                                IsUnlimited Value
                                ----------- -----
                                      False 1563669133B

    Open in new window

    How can I just get the value?

    Author Comment

    LVL 37

    Assisted Solution

    by:Jamie McKillop
    Add .value to the end.


    Author Comment

    Awesome.  Just what I needed.

    Featured Post

    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

    Join & Write a Comment

    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
    In this video we show how to create a Distribution Group 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 Recipients >>…
    The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

    734 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

    22 Experts available now in Live!

    Get 1:1 Help Now