Do Your Exchange Online Admin Tasks with PowerShell

There are some things in Exchange that you just need to use PowerShell for.  If you use Exchange Online or Office 365, the web portal exposes a lot of the admin functionality that you might need, but there are certain actions that require PowerShell.

Accessing the Exchange PowerShell cmdlets on a local server is one thing, but accessing those cmdlets in a hosted environment can be a little trickier.  After I had to type these a half-dozen times, my brain wasn’t getting it quite yet, so I build a little script that covers what you need to need to establish a connection to the remote Exchange environment.

Continue reading “Do Your Exchange Online Admin Tasks with PowerShell”

Exchange 2010: Database Copies with PowerShell

I needed a quick and dirty method to add database copies to other servers in an Exchange 2010 Database Availability Group (DAG).  I had three servers, each with 10 databases.  Each one of those databases should have a copy on the other two servers. 

Now, this is painful if you have to use the GUI to do it – not that it takes a lot, but it’s time consuming.  The Add-MailboxDatabaseCopy cmdlet is very helpful in PowerShell, but still I wanted to automate it since my naming conventions were pretty standard.

So, I wrote a PowerShell script to automate this process.  Essentially, the script has a few variables and I dome some loop magic to drop everything into place. 

This script is quick and dirty for a lab environment.  Keep in mind that this doesn’t do any error checking and there is no validation to see if a database is already homed to a server.  This just uses the cmdlet to try to create the database copy; if it is successful, you’re good to go.  If it fails, the script just keeps on rolling.  No harm, no foul.

Exchange 2010 Pre-Req Setup (Updated)

A couple of months back I wrote a post on how to automatically install pre-requisites for Exchange 2010 on a Windows 2008 (including R2) server.

I specifically talked about a method for doing this with ServerManagerCmd.exe, which is included with Windows Server 2008.  However, in Windows Server 2008 R2, ServerManagerCmd is deprecated and the recommended method is to use PowerShell (as pointed out by my buddy, Josh). 

The Add-WindowsFeature cmdlet in PowerShell provides the capability to add individual Windows features directly from a script.  You can use Get-WindowsFeature to obtain a detailed list of available features, ones that are installed, and their “official” name if you wish to install them via PowerShell.

To install the required pre-reqs for Exchange 2010, from a PowerShell prompt, be sure to add the Server Manager module so the Add-WindowsFeature and Get-WindowsFeature cmdlets are available.

Import-Module ServerManager

Once you have imported the module, then you can use Add-WindowsFeature to take care of the rest.

Add-WindowsFeature -Name RSAT-ADDS-Tools, RPC-over-HTTP-proxy, NET-HTTP-Activation, Web-Dyn-Compression, Web-Windows-Auth, Web-Digest-Auth, Web-Basic-Auth, Web-Lgcy-Mgmt-Console, Web-Metabase, Web-ISAPI-Ext, Web-Server -Concurrent

PowerShell with Compellent and Exchange 2010

I’ve been doing lots of work in the lab lately with Exchange 2010 to understand all the new changes and how it works with the Compellent Storage Center.

With Exchange 2010, the concept of Storage Groups no longer exists.  Databases are the sole object and are a peer to the server now.  Database names must be unique, but can be moved from server to server as necessary.

In the past, I’ve shared some scripts on how to provision storage for an Exchange 2007 environment.  I’ve slightly reworked this script to account for no longer needing storage groups, but to also automatically create the mailbox database on the Exchange Server and mount it when completed.

There are a number of areas in which this script can be improved and that I will continue to work on. 

Exception handling is very important.  Understanding how your code could react in particular scenarios is difficult, but you don’t want your script to bomb out every time you run it either.  I’ve build quite a bit of exception handling into the mapping and mounting portions of the script, but this can always be reworked to be improved.

Quick Hit: Installing Pre-Reqs for Exchange 2010

This can be a bit tricky … and you can either get enough exposure by doing it so many times that you just know what needs to be installed before you start, or you can get through a bunch of steps in the setup before it stops to tell you that the right things aren’t installed and can’t continue.

Exchange 2010 requires Windows Server 2008 or Windows Server 2008 R2.  You can use Server Manager to install the Web Server (IIS) role, however, there are many, many pieces to IIS that are broken out into individual components in 2008.  Which ones are required to get you the prerequisites you need to get through the Exchange 2010 installation?

Instead, consider using ServerManagerCmd.exe, which is built-in in Windows 2008 to automate the role installation for you.  This command is very useful in installing new components and making sure that you have the pieces you need.  From a command line, run:

ServerManagerCmd -i RSAT-ADDS Web-Server Web-Metabase Web-Lgcy-Mgmt-Console Web-ISAPI-Ext NET-HTTP-Activation Web-Basic-Auth Web-Digest-Auth Web-Windows-Auth Web-Dyn-Compression RPC-over-HTTP-proxy Web-Net-Ext –Restart

This will install the necessary components including ADDS which needs to be installed for remote administration of Active Directory and for the Exchange 2010 schema extensions to be installed.  Once the command completes, the server will restart.  After that, you’re ready for your Exchange 2010 installation.

You can find more information on ServerManagerCmd.exe on Technet.

Quick Hit: Export-Mailbox Cmdlet in Exchange 2007

Ever needed to export the contents of an entire mailbox (or mailboxes)?  The Export-Mailbox cmdlet that is available via the Exchange 2007 PowerShell console can export each mailbox to a PST file.  In addition, Import-Mailbox can be used to import the contents of a PST back into an existing Exchange 2007 mailbox.

Syntax:

Export-Mailbox –Identity <mailbox alias> –PSTFolderPath <path to PST file>

There are a number of additional parameters available to filter the contents and tweet the configuration of what exactly is exported.  Using Export-Mailbox can be very time-consuming. a 200 MB mailbox can take 20 minutes or more (or did so in my tests).

A few things to remember when using Export-Mailbox:

  1. The account running the cmdlet must have full permissions to the mailbox in order for the export to complete successfully.

    MAPI Error Image

  2. The export will export all mail contents including the contents of the dumpster for that mailbox.
  3. Export-Mailbox requires that Outlook 2003 SP2 or later is installed on the machine from which the command is executed. 
  4. Export-Mailbox can only be run using the 32-bit version of the management tools.  This means that you have will have to load the 32-bit management tools on a workstation, since production environments of Exchange 2007 run in 64-bit environments.

This is a perfect alternative to what required ExMerge in the past.

How Does Exchange 2010 Impact Storage?

Last week I had to opportunity to setup Exchange 2010, which is currently in beta.  Microsoft had a great story about the improvements with Exchange 2007, particularly around storage and IO.  Although I was not a big fan of role-based implementations, this type of setup has allowed for great scalability and also has made some components of Exchange viable candidates for virtualization.

Exchange 2010 uses some cool new technologies like PowerShell v2 and Windows Remote Management v2, both of which are still CTP.

Microsoft has improved the performance of Exchange again in Exchange 2010.  When Exchange 2007 was released, Microsoft boasted a 70% decrease in IO.  For example, an Exchange 2003 heavy mailbox profile used 1 IOPS/mailbox, while a Exchange 2007 heavy mailbox profile only uses .32 IOPS/mailbox.

In Exchange 2010, you can expect up to a 50% reduction in disk IO from Exchange 2007 levels.  This means that more disks meet the minimum performance required to run Exchange, driving down storage costs.  In addition, IO patterns have been optimized and are not “bursty” like they have been in previous versions.

With the ability to replicate up to 16 copies of each mailbox database, automatic page patching takes advantage of these replicated copies by using them as the source for repairs in the event page corruption or other minor database glitches occur.  Sounds pretty cool!

The schema has been revamped and message/header content is now stored in a single table.  In addition, Single Instance Storage is out, but automatic attachment compression is in. 

One of the bigger changes in Exchange 2007 was the page in the database page size from 4K to 8K.  In Exchange 2010, this changes again to 32K, allowing for larger block IO.  This charge is particularly helpful in keeping chunks of data together like attachments instead of having them scatter all about.

Exchange 2010 is expected to be released in late 2009, but the beta is available for download at http://www.microsoft.com/exchange/2010/en/us/try-it.aspx.

Should You Virtualize Your Exchange 2007 SP1 Environment?

Lots of folks are trying to save money in their data centers by optimizing their infrastructure usage with virtualization.

Interestingly enough, with the release of Hyper-V and Microsoft’s program for hardware virtualization vendors, the support policy for Exchange and other applications has changed.

A couple of weeks ago, a post appeared on the Exchange Team Blog asking the question, “Should you virtualize your Exchange 2007 environment?” They lay out several scenarios where virtualizing at least some of the Exchange infrastructure might make sense.

Take a look here.

Using Powershell To Generate Test Mailboxes

There are situations where you may want to generate a number of test mailboxes whether it be for a demo or another scenario.  With Exchange 2007, you can leverage Powershell cmdlets to complete this process for you in just seconds.

First, I start out with the a CSV file that contains a limited number of columns, basically the minimum needed to create an Active Directory user account and mailbox-enable it.  Since I have a passion for baseball, my test CSV file is a tribute to some of my favorite players in history.  This is what the sample users.csv file looks like:

UPN,FirstName,LastName,Password
bruth,Babe,Ruth,TestP@ssword1!
mmantle,Mickey,Mantle,TestP@ssword1!
hwagner,Honus,Wagner,TestP@ssword1!
brobinson,Brooks,Robinson,TestP@ssword1!
yberra,Yogi,Berra,TestP@ssword1!
kpuckett,Kirby,Puckett,TestP@ssword1!
rcarew,Rod,Carew,TestP@ssword1!
hkillebrew,Harmon,Killebrew,TestP@ssword1!
twilliams,Ted,Williams,TestP@ssword1!
jdimaggio,Joe,DiMaggio,TestP@ssword1!

Next, it only takes a couple lines of code for us to generate the accounts and mailboxes.  You can take this code and save it into a file named something like createmailboxes.ps1.  This is what the script should look like:

# Test Mailbox Creation Script

# Variables Used Globally
$database = “First Storage GroupMailbox Database”
$ou = “Users”
$upnsuffix = “@e2k7test.local”

import-csv users.csv | foreach {$pass = ConvertTo-SecureString $_.Password -AsPlainText -Force; New-Mailbox -Name ($_.FirstName+” “+$_.LastName) -Password $pass -UserPrincipalName ($_.UPN+$upnsuffix) -Database $database -OrganizationalUnit $ou -FirstName $_.FirstName -LastName $_.LastName -DisplayName ($_.FirstName+” “+$_.LastName)}

In my script I include some variables that I reuse for all of my users.  In this case, they are all going to be part of the same organizational unit (OU) in Active Directory and their mailboxes will all be part of the same mailbox database.  They are also part of the same domain so the suffix for their User Principal Name (UPN) will be the same.

Literally, the meat of the script is just one line of code thanks for the piping you can do in Powershell.

The import-csv cmdlet takes in a comma-separated text file and lets us read its contents like a data object.  Basically we’re taking the contents of the CSV file and passing it into the next segment of code which is the “For Each” block.

Since we want to create an account and mailbox for each line in the CSV file, we’ll do that line by line processing within the “For Each” block.  The first command within that block is where we’ll save the password as a variable.  Since the password can’t be passed into the cmdlet as plain text, we have to convert it to a secure string using the ConvertTo-SecureString cmdlet.  We pass in the plain text password and it returns a secure string that can be used.

Next we call the New-Mailbox cmdlet which will create the account and mailbox enable it.  We’ll pass in information like the name of the account, first name, last name, display name, UPN, mailbox database, OU, and password.  There are additional fields that you can include, but are not required.

We can access the different “fields” from the CSV by calling them with the $_.ColumnName format as you can see in the script sample. 

This clearly simplifies the process of bulk account creation and provisioning for Exchange.  We’ll work on continuing to evolve this into a more complex script that adds some additional functionality.

Fixing Corrupted Performance Counters

Every once in a while I run into a case where my Windows performance counters go a little whacky.  That is, when I am in Performance Monitor, my objects and their respective counters display text are replaced with a 3-4 integer description instead.  I have no idea how this happens, but this tends to break other things, particularly the Jetstress application which relies on performance counters for it’s data.

Counter corruption can be seen typically when adding a counter to monitor where the performance object and counters actual names are replaced by a numeric description.

To restore the performance counters, start a Command Prompt and run:

c:\>LODCTR /R C:\WINDOWS\SYSTEM32\PerfStringBackup.ini

The result will be that when you restart Performance Monitor, your counters again will be readable.  If you are running the x64 version of Windows Server, make sure that you replace SYSTEM32 with SYSWOW64 as this is where the INI file is located. LODCTR can be used to load or re-load as well as repair the performance counters.