Exchange Exchange
A community dedicated to Exchange and related technology.

Working with get-mailbox in PowerShell

rated by 0 users
This post has 6 Replies | 3 Followers

Top 10 Contributor
Points 3,290
Joel Stidley Posted: 08-17-2006 12:02 AM

One of the basic commands an Exchange administrator will need to use is get-mailbox .  Lets examine some of the basics.

get-mailbox

This will return all mailboxes in a table format.

get-mailbox jstidley

This will return information about my mailbox in a table format.

get-mailbox jstidley | format-list

This will return all attributes of my mailbox in a list format.

get-mailbox *David*

This returns a list of all mailboxes of users with David in the name.

One of the most powerful features of PowerShell is the ability to pipeline.  Now if we wanted to change the send quota for ALL users we don't have to go to each mailbox and change it, we can pipeline the output of get-mailbox to set-mailbox.

get-mailbox | set-mailbox -prohibitsendquota 500MB

This will set all mailboxes to have a send quota of 500MB

- Joel

  • | Post Points: 20

what is the syntax to apply the -filter option and how do you pipe it to a file?

 thanks
 

  • | Post Points: 20
Top 10 Contributor
Points 3,290

Often people will show using the where to do filtering, however this filtering is done on the client side. The -filter option allows the server to do the filter before the results are sent to the client.

 To use -filter first you need to know what properties are available to filter for each command.  A good reference for RTM is here and here.  Exchange Server 2007 SP1 makes some changes to this, the full list of filterable properties for SP1 can be found here.

Lets take a nice easy example.  We can filter by DisplayName when working with Get-Mailbox (according to the links above)

Get-Mailbox -filter "DisplayName -like '*John*'"

This will return all mailboxes with a display names that contain john. 

 To export the resulting list to a text file you can simply pipe to out-file

Get-Mailbox -filter "DisplayName -like '*John*'" | out-file C:\MailboxList.txt

 

 

 

 

- Joel

 thanks this is it. Is there a reference on this somewhere a book that you would recommend? I looked over the online help but I am having trouble reading them...

 

thanks 

  • | Post Points: 20
Top 10 Contributor
Points 3,290

I would recommend my book, but it won't be out for a few months.  It covers a lot of the PowerShell concepts related to Exchange Server 2007.  There are a number of example scripts and real world scenarios.

If you choose to you can order it here:  http://www.amazon.com/gp/product/0470226447?ie=UTF8&tag=exchaexcha-20&link_code=as3&camp=211189&creative=373489&creativeASIN=0470226447

Otherwise check back here often for more tips.

 

 

 

- Joel

  • | Post Points: 5

Hi Joel,

First of all I am new to scripting, I have been using it with exchange 2007 and I seem to be picking it up there seems to be loads of different ways to do things. I think I may get your book as well.

I am trying to output some information to either a CSV file or an html file but when I run either of my commands they are not filtering (these are not my commands I got them from Matt Byrd from the exchange Blogg, well the CSV one is his and I have changed the HTML one)

HTML - get-mailbox -Filter "UseDatabaseQuotaDefaults -eq `$false" -ResultSize Unlimited | convertto-html | set-content c:\temp\export.html

CSV - get-mailbox -Filter "UseDatabaseQuotaDefaults -eq `$false" -ResultSize Unlimited | export-csv c:\temp\export.csv

I am also looking to add the following to the script but I am not sure where to start :-) "IssueWarningQuota" and "ProhibitSendReceiveQuota"

Thanks in advance.

Regards

John brines

  • | Post Points: 0
Top 10 Contributor
Points 3,290

John,

These are good questions. When you say "they are not filtering" is it that the results aren't filtered to the right results or the actual data columns aren't correct.

Secondly, if you are using export-csv, you want to use select-object to add the fields that you want to be piped out. As an example you could run:

get-mailbox -Filter "UseDatabaseQuotaDefaults -eq `$false" -ResultSize Unlimited | select DisplayName, UseDatabaseQuotaDefaults, IssueWarningQuota, ProhibitSendReceiveQuota | export-csv C:\text.csv

- Joel

Page 1 of 1 (7 items) | RSS
© 2003-2008 NamedPipes Consulting. All other company and product names are property of their owners.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems