Can Powershell insert mailbox size query results into SQL?

Posted on 2011-10-27
Medium Priority
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
  • 3
  • 2
LVL 37

Accepted Solution

Jamie McKillop earned 2000 total points
ID: 37039489

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: http://learningpcs.blogspot.com/2010/08/powershell-insert-data-into-sql-server.html


Author Comment

ID: 37057853
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

ID: 37071017
LVL 37

Assisted Solution

by:Jamie McKillop
Jamie McKillop earned 2000 total points
ID: 37071109
Add .value to the end.


Author Comment

ID: 37071340
Awesome.  Just what I needed.

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
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…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
Suggested Courses

850 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