Exchange Exchange
A community dedicated to Exchange and related technology.

Working with get-mailbox in PowerShell

rated by 0 users
This post has 16 Replies | 7 Followers

Top 10 Contributor
Points 3,290
Joel Stidley Posted: Thu, Aug 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
mzpwu replied on Fri, Sep 21 2007 4:59 PM

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

mzpwu replied on Mon, Oct 1 2007 8:27 PM

 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

Paul replied on Wed, Feb 3 2010 12:50 PM

Hi Joel,

Forgive me, as I am a complete newbie to the PS world.

 

My customer is running a Windows 2008 box (64-bit) with Exchange 2007. I am trying to use PS to change the default smtp address (from @ChangeCase.com to @changecase.com), but I receive the following error:

"The term 'get-mailbox' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again."

I am running PS in the D:\Program Files\Microsoft\Exchange Server directory, with the script located in that same directory.

 

Any suggestions?

 

Thank you,

 

Paul-

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

Are your running the script from the Exchange Management Shell or from a Windows PowerShell?  The Exchange Managment snapin needs to be loaded into PowerShell in order to use the Exchange cmdlets. When you run the Exchange Management Shell it is supposed to load that snapin automatically.

You can see if the Exchange snapin is loaded by running Get-PSSnapin

To add the Exchange snapin you can run: add-PSSnapIn Microsoft.Exchange

 

 

- Joel

  • | Post Points: 0

Hello. I'm Santiago from Argentina. I am running a Windows Server 2003 with Exchange 2007 and must submit a report containing the amount of e-mails for each employee. The problem is that the command GetMailboxStatistics. does not refresh the information if someone erase any e-mail

Are there any command to be able to solve this problem? I hope you understand me


Grateful

Santiago

  • | Post Points: 0
solaris replied on Fri, Apr 2 2010 11:37 AM

Hi

I am trying to search for key words on all mailboxes.

1. i open Exchange Management Shell

2. change the directory to d:\databases

a. name of database: Mailbox Database.edb

3. performed a query by typing:  get-mailbox -Database 'Mailbox Database.edb' | Export-Mailbox -SubjectKeywords "PLA" -TargetMailbox administrator -TargetFolder 'PLA'

a. I get the following error message: Get-Mailbox : Database "DEC-MAIL2.com\Mailbox Database.edb" was not
 found. Please make sure you have typed it correctly.
At line:1 char:12

That is the correct name of the database. Does it not like spaces inbetween "Mailbox" and "Database.edb"

Can anyone shed some light as to what i am doing wrong?

thanks,

Solaris

 

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

You need to use the name of the Mailbox database as shown in EMS or EMC, not the file name. If you run Get-MailboxDatabase -Server DEC-MAIL2, you should get a list of the names of the databases on your server.

- Joel

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

Thanks for your question. Can  you post the command you are running and the output along with what you want different on the report?

- Joel

  • | Post Points: 0
solaris replied on Mon, Apr 5 2010 5:34 PM

thanks for the quick reply. I figured it out.

I have to type in "get-mailboxdatabase" in order to determine the name.

 

 

  • | Post Points: 0
172pilot replied on Tue, Apr 27 2010 7:45 AM

This is a great reference, but I have one question that I haven't found answered anywhere....

When doing an ldap query, I could choose a search scope to determine if I'd get results from all the child OUs, or just the specific OU I did the search from...


When doing a "get-mailbox -OrganizationalUnit <someou>", is there any similar feature?  Sometimes I want all the mailboxes in the child OUs, which is the default behaviour, but sometimes I only want the mailboxes in that specific OU, and I can't find a way to do it...

Any ideas?  I guess I could pipe the results through a "where" clause that will return only the ones with that specific OU, but that seems slow and inefficient..  There must be a better way...??

-Steve

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

There isn't anything built into the Exchange 2007 cmdlets to do this. You would have this pass this through another filter, or you could also sort the results by OU to more easily pick out where the mailboxes exist.

 

- Joel

  • | Post Points: 0

Hello,

 

I'm trying to find a way to recover statistics mailbox remotely.

For example I can retrieve the remote process with
$cred = .\import-credential.ps1 pass.txt
Invoke-Command { Get-Process } -ComputerName wks0027 -Credential $cred

I'm running my script on a windows xp.
I saw there was the parameter "credential" for the command get-mailbox.
But what setting I should use to specify the remote machine to ask?

thk,

jeff

  • | Post Points: 0
Page 1 of 1 (17 items) | RSS
© 2003-2009 NamedPipes Consulting. All other company and product names are property of their owners.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems