Saturday, March 20, 2010

GetMailbox With OU

Haylo,

The end user's requirement was to get the mailbox size limits and current sizes of a particular geographical location.

First I ran the command to get the mailbox name, alias and size. Its easy with a get-mailbox command.

get-mailbox -organizationalunit "OU=United States,DC=example,dc=com" -resultsize unlimited select displayname, alias, prohibitsendreceivequota, database export-csv c:\data2.csv

I used the -resultsize unlimited because otherwise exchange would have only returned 1000 rows to me, and I would have thought that it was sufficient. With this parameter I am sure I get all the data.

Get-mailbox will return all the columns to me, so if you want to see the data you can get from get-mailbox, then run it without the 'select' pipe.

get-mailbox -organizationalunit "OU=United States,DC=logistics,dc=intra" -resultsize unlimited get-mailboxstatistics select Displayname, alias, TotalItemSize export-csv c:\data4.csv

Since get-mailboxstatistics doesn't support 'OU' and get-mailbox does not return 'Item Size', therefore I used something called 'piping'. Piping allows us to send the results of one command into another command, so that the results are limited. In the above command, the results of get-mailbox are sent to get-mailboxstatistics.

Unfortunately, piping only returns data from one command (at least as far as I know). Therefore we had two .csvs and the following small filtering jobs.

a. Needed to combine the data of the 2 csvs. I sorted the data by display name and combined the columns in excel.

b. Needed to change the KBs, Bytes into MBs. I could have done through a query as well, as Ghassan did, but it was complicating my query a bit, so I didn't try it. I normally don’t use commands/queries which I don't understand, therefore I just used excel formulae to convert it.

c. ProhibitSendReceiveQuota, was showing 'unlimited' in many mailboxes. This does not mean that all of these users have unlimited mailbox sizes. This only means that they are being limited at the database level. So for this I used Excel's find/replace feature to find the size of the database and replace it with the actual size limit.

The above is good for one-off cases, but if you have a frequent reporting requirement, then I would advise you to look a bit into scripting.

As always all and any suggestions are more than welcome.

Cheerz