Technet Evening Exchange 2007 – Q&A and Powershell scripts Part II


Let’s continue with powershell and the next thing I showed was how
to create and test a script. The script we wanted to create was a move
mailbox script. Not just a move mailbox but one where we searched for
the top 3 biggest mailboxes.

First let me explain a little bit the mailboxstatistics command and how we can get the top 3 mailboxes in size.

get-mailboxstatisctics

This
command returns the mailboxes with some statistical information like
the number of items, last logon time. See the screenshot for more info

Now that we have the mailbox stats we want to sort them.

get-mailboxstatisctics | sort totalitemcount –desc

 

 

 

(get-mailboxstatisctics | sort totalitemcount –desc)[0..2]

This command returns the same results as the previous command but sorts it based on the number of items in the mailboxes.

 

Same result but shows only the top 3 (from 0..2) mailboxes

You know now how to get stats, sort them and filter the top 3 out of it lets continue with the script we created.

The technetdemo.msh script:

param($server=$(read-host “Target Server”))

 

new-storagegroup DemoTechnet -server $server | out-null

new-mailboxdatabase MBX01 -storage DemoTechnet | mount-database

 

Write-host “Database Created”

 

$mbxset=(get-mailboxstatistics -server smbex01 | sort itemcount -desc)[0..2] | foreach {get-mailbox $_.LegacyDN}

 

$mbxset | move-mailbox -targetdatabase MBX01 -whatif

 

Let me explain some of the new commands we used in this script.

The param command is used to pass parameters to the scripts, in this case we are asking for the target server.

The out-null command is obvious, do not write output.

The Write-host command will write the message to the host. This can be useful to have some information about the status of your script.

The “$mbxset=” command is to create a variable with
in this example the get-mailboxstatistics command, this means that the
mbxset will contain the legacydn name of the top 3 mailboxes.

We can now use the variable and pipe it to a move-mailbox command to move those mailboxes.

I recommend to use the what-if or –validate command to see what the result of the move mailbox will be.

You can now just run the script in the shell by referring to the file.

The biggest advantage of Powershell scripting is that you can test
each line of your script before actually hitting the complete script.
In VBscripting you had to run the complete script and wait and see or
use a debugger to debug each line.

 

The last part of the Powershell scripting is reporting. I explained
that there some command to do diagnostics and some commands to do
reporting.

For the diagnostics part there are commands like :

 

Test-mapiconnectivity

 

 

Test-Servicehealth

This command will test the mapi connectivity for all mailboxes.

 

This command will look at the different server roles and return the services that are running and which one are not.

See screenshot.

For reporting there are commands like export-csv which lets you
export the information to a csv file there are also some scripts that
we have created like out-html and out-chart which outputs information
to a html file or to a chart. (See screenshots for an example)

The following example will get the mailbox stats, sort them by itemcount and output certain information to a html file:

Get-mailboxstatistics
| sort totalitemcount –desc | select mailboxdisplayname,
totalitemcount, totalitemsize | out-html | out-file
c:\powershell\mailboxstats.html

The last example will do the same but output into a chart instead of html.

Get-mailboxstatistics | sort totalitemcount –desc | out-chart mailboxdisplayname, totalitemcount –outfile report1

So far for the Powershell scripting.

The next item on this post was some Q & A we got after the session:

Q: Can you schedule a Powershell script like the charting script?

Answer: Yes you can here is an example

msh.exe
-mshconsole ‘c:\program files\microsoft\exchange
server\bin\exshell.mcf1’ -command ‘get-mailboxstatistics -server
server1 | d:\scripts\out-chart Identity ItemCount -filename
d:\charts\chart.jpg’

Q: Will there still be a standard and Enterprise edition of Exchange?

Answer: We did not disclosed any licensing on Exchange 2007 yet.

Q: Will there only be support of 64 bit?

Answer: There will only be 64bit support, no support for Itanium only x64 based systems.

Q: Unified Messaging Video?

Answer: I told you I would look after the UM video and
unfortunately there is not yet a public version of the video available
however here is a link to another video which is a cool demo on the LCR
and CCR technology. http://msexchangeteam.com/videos/9/drandha/entry427787.aspx

If you have other questions please mail (Arlindo.alves@microsoft.com) me and I will try to answer them.

You can now download the presentation : http://www.microsoft.com/belux/technet/nl/events/presentations.mspx

 

Tags: Powershell, Monad, Exchange 2007

 

Comments (7)

  1. DBMwS says:

    In,

    $mbxset=(get-mailboxstatistics -server smbex01 | sort itemcount -desc)[0..2] | for-each {get-mailbox $_.LegacyDN}

    Shoudln’t "for-each" be changed to "foreach"?

  2. applepwc says:

    Could you share your out-chat function?

    Thanks

  3. aralves says:

    Yes it definitely should be foreach must be a typ o I will change it

  4. Anonymous says:

    “What is Microsoft PowerShell, and what does it mean to migration from Domino to Exchange Server 2007?” …

  5. Anonymous says:

    Yes it’s there you can now download Exchange Server 2007 Beta 2 from here.     You want to have…

  6. Anonymous says:

    Ano, je to tady. Exchange 2007 Beta 2 volně ke stažení!

    Začíná to vypadat na to, že mnoho chystaných…