Welcome to TechNet Blogs Sign in | Join | Help

Syndication

News

  • My Twitter
  • 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

     

    Published Monday, June 12, 2006 11:52 AM by aralves

    Comment Notification

    If you would like to receive an email when updates are made to this post, please register here

    Subscribe to this post's comments using RSS

    Comments

    # re: Technet Evening Exchange 2007 – Q&A and Powershell scripts Part II @ Thursday, June 15, 2006 9:39 PM

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

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

    DBMwS

    # re: Technet Evening Exchange 2007 – Q&A and Powershell scripts Part II @ Friday, June 16, 2006 11:20 AM

    Could you share your out-chat function?

    Thanks

    applepwc

    # re: Technet Evening Exchange 2007 – Q&A and Powershell scripts Part II @ Saturday, June 17, 2006 3:44 AM

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

    aralves

    # PowerShell and Migrations @ Friday, June 23, 2006 5:05 PM

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

    Tools for Moving to a Microsoft Collaboration Platform

    # PowerShell and Migrations @ Friday, June 23, 2006 5:58 PM

    http://blogs.technet.com/collabtools/archive/2006/06/23/438504.aspx
     
    Good article on PowerShell...

    Ron Crumbaker at myITforum.com, Inc.

    # Exchange 2007 Beta 2 - Out now! @ Monday, July 24, 2006 4:48 AM

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

    [MSFT-BE] Arlindo's Blog - IT Pro Evangelist

    # Exchange 2007 Beta 2 - Můžete začít zkoušet! @ Monday, July 24, 2006 7:30 AM

    Ano, je to tady. Exchange 2007 Beta 2 volně ke stažení!
    Začíná to vypadat na to, že mnoho chystaných...

    TechNet Blog CZ, SK

    Leave a Comment

    (required) 
    required 
    (required) 
    © 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
    Page view tracker