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
what is the syntax to apply the -filter option and how do you pipe it to a file?
thanks
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
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...
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.
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
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
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-
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