Tuesday 22 July 2008

Exchange 2003, WMI and Powershell - Part 1 (Get Mailbox Info)

OK, so I had some fun making a Powergui Powerpack for Exchange 2003, but its probably about time I wrote about how to do this natively in Powershell.

There is a lot of information you can get out of Exchange 2003 using WMI. Yikes, you might say if you previously thought about doing that with VBScript; however, with Powershell its easy!

We simply use the Get-WMIObject cmdlet, use the ExchangeV2 namespace and Exchange_Mailbox class and connect to the Exchange Server in question.

(You can find all about the Exchange_Mailbox class over on MSDN. Sysadmins amongst you might think MSDN is only for developers, but the Exchange WMI pages are pretty straightforward and all contain a very nice example in VBScript where you can figure most stuff out which is available to you.)

This will return you all the mailbox objects on that server. We then use some basic sorting and selecting to present the info nicely.


Get-WMIObject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName | sort-object MailboxDisplayName | format-table MailboxDisplayName,Servername,StorageGroupName,StoreName,Size

3 comments:

Anonymous said...

Cool. I have used it to get a list of all users mailbox consumption on an Exchange 2003 server that was out of reach.

I only needed the user and size so this is what I used:
Get-WMIObject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ServerName | Sort-Object Siz
e -Descending | format-table MailboxDisplayName,Size

I was wondering, is there a way to get the username instead of the displayname?

Thanks for a great script.
Kasper

JoelThor said...

You would need to also pull the LegacyDN attribute, and then leverage (or pipe) that to a Get-Mailbox or Get-ADUser command to pull other attributes, like UserName.

JoelThore said...

You would need to also pull the LegacyDN attribute, and then leverage (or pipe) that to a Get-Mailbox or Get-ADUser command to pull other attributes, like UserName.