Starting Exchange Services after a Power Failure

In my environment, with a virtualized SBS 2011 Standard, there are occasionally Microsoft Exchange 2010 services that don't properly restart if there has been an abrupt power failure on the Hyper-V host. (Don't ask.)

Now, of course, the first time this happened, I just logged in to the server and started the services. But when it happened again, it's time to write a script. And it was a fun script, since it uses WMI and PowerShell remoting and other fun stuff.

# Script to start Exchange services on SBS 2011 Server after power failure
# Accepts a parameter of the exchange server name, but defaults to SRV2 if none entered
# Assumes you are logged in to the domain with Domain Admin credentials
# Created: 14/03/2011 by Charlie
# ModHist: 15/03/11 -switched to using WMI in the session to get StartMode
param ($ExchSrv = "SRV2" )

# first, open a session to the Exchange server
$srv = New-PSSession $ExchSrv

#Now use Invoke-Command with -Session
Invoke-Command -Session $srv -scriptblock {
   $exsvc = gwmi win32_service | Where-Object {$_.Name -like "MsExch*" `
     -and $_.StartMode -eq "Auto"   -and $_.State -eq "Stopped" }
   if ($exsvc ) {
      foreach ($svc in $exsvc ) {
         Start-Service $

The if statement in there is to prevent an error if all the services are running. Of course, for this script to work as it's written, you'll need to run it from a workstation in the SBS domain, and you'll have to enable PowerShell remoting on both the server and the client. If you haven't done that yet, I've posted a quick setup guide on TechNet.

I've posted this script up to the Microsoft Script Center, so if you have comments or suggestions to improve it, please comment there.


Changing the Maximum Message Size in Exchange 2010

This little script will change the maximum message size for an Exchange 2010 server. It’s not  tested and designed for use in very large Exchange organizations, but has been tested and works on single Exchange 2010 server environments such as Windows Small Business Server 2011 Standard.

edited: 19/2/2011. reminded by Brian Desmond that I really should use param($MaxSize). Thanks!

# Change-ExchSize.ps1
# Script to change the size of the maximum send and receive for
# a Windows SBS 2011 Standard installation with Exchange 2010
# Expects: maximum size parameter in MB or prompts
# Created: 19/2/2011
# ModHist: 19/2/2011 (changed to use param(). Thanks Brian

if (! $MaxSize ) {
$MaxSize = Read-Host "What's the max size(in MB) you want for all mailboxes? "
$stMaxSize = "$MaxSize" + "MB"

"Setting Maximum Send and Receive Transport Size to: $stMaxSize"
Set-TransportConfig -MaxSendSize $stMaxSize -MaxReceiveSize $stMaxSize
Get-TransportConfig | ft -maxsendsize,maxreceivesize

"Setting Maximum Send and Receive Connectors to: $stMaxSize"
$ReceiveConnectors = Get-ReceiveConnector
$SendConnectors = Get-SendConnector

ForEach ($Connector in $ReceiveConnectors ) {
Set-ReceiveConnector -Identity $ -MaxMessageSize $stMaxSize

ForEach ($Connector in $SendConnectors ) {
Set-SendConnector -Identity $ -MaxMessageSize $stMaxSize

"The Maximum Receive Connector size has been set to: "
Get-ReceiveConnector | ft Name, MaxMessageSize

"The Maximum Send Connector size has been set to: "
Get-SendConnector | ft Name, MaxMessageSize