Posts
47
Comments
55
Trackbacks
0
Get-Mailbox, the most popular cmdlet

I just noticed that I use Get-Mailbox everywhere in my examples. Why is that? I suppose its because this a) Exchange is all about Mailboxes (if you didn't know, Exchange is an e-mail / collaboration server) and b) its so easy to use. The basic pattern for Get-Mailbox is below:  

Get-Mailbox

If you just run this, the cmdlet will return upto 1000 mailbox enabled users. Why 1000? Well we have to cap our results somewhere, as if we returned everything, very large amounts of data would be returned. Small companies will never notice. Large companies can do:

Get-Mailbox -resultsize 99999

Or whatever number of results they want returned. The cool thing is that you can also do:

Get-Mailbox -resultsize Unlimited

Which returns all mailboxes. BTW: This same pattern can be applied to all the other recipient cmdlets as well as queue viewer cmdlets. So what else can get-mailbox cmdlet do? A lot. The next simplest example is to get one particular user:

Get-Mailbox domain\username
Get-Mailbox username 
Get-Mailbox user@foo.com
Get-Mailbox -identity username

You'll note that many different formats are accepted (in fact, you can pass in GUIDs and DNs too!). The 2nd important thing to note is that -identity is a positional parameter. Positional means that if you omit -identity on the cmdline, the first token is assumed to be the argument to -identity. In simple words, it saves you some typing. For example: ever wanted to get all the mailboxes that reside on a particular mailbox database? There you go:  

Get-Mailbox -database Get-Mailbox -database server1\sg2\mdb1

Note the format that I passed into -database: server\storagegroup\mdb. You can also pass in just the name, we will try and match it against all databases on the local server, if none are found, we'll let you know. Much better than passing DNs or GUIDs around.  But wait, what if you wanted to see all mailboxes that reside on a particular server?  

Get-Mailbox -server server1

Well that's all good, but what if you wanted to find some user based on some more complex query? That's why we have the -filter option:

Get-Mailbox -filter { Name -like '*vivek*' -and Company -eq 'viveksharma.com'  }

This is called server side filtering. The recipient cmdlets and the queue cmdlets support this concept. Basically it takes the query you specify and only returns those results. Note, in Monad you can always do client side filtering on any object even in the cmdlet does not support any advanced filtering. The moral equivalent to the previous cmd in client side filtering terms is:

Get-Mailbox | where { $_.Name -like '*vivek' -and $_.Company -eq 'viveksharma.com' }

Not much different is it? Server side filtering is useful for cmdlets that return a large set of data, but in general we rely on client side filtering to do much of the work in Exchange. Ok, one last freebie, after this I will have to charge. Just kidding of course. We optimized some cases just for you:

Get-Mailbox *vivek*

That will run a server side wildcard search across all mailbox user names (and smtp addresses too). So you can do things like this:

Get-Mailbox *vivek* | format-table Name,*quota*

Which will get all the mailboxes that have 'vivek' in their name and show you table output with their name, and various quota sizes. Now show me the vbscript equivalent of that!

posted on Thursday, May 04, 2006 10:05 PM Print
Comments
Gravatar
# re: Get-Mailbox, the most popular cmdlet
Ganesh
7/2/2008 2:05 AM
  
how to find out database size through shell command
Gravatar
# re: Get-Mailbox, the most popular cmdlet
Vivek
8/19/2008 7:56 PM
  
You can use get-mailboxstatistics on a per user basis to get a total mailbox size. To get it for all the users on a database: get-database | get-mailboxstatistics should work, but then you have to sum up all the entries. You can use measure-object -property for that part.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 5 and 2 and type the answer here:
News
A little slow these days as I'm busy working on exchangelabs.com. I will try and post tidbits when I get some time. Enjoy the older posts till then!