Exchangemaster GmbH company logo

Exchangemaster GmbH - A Swiss IT Consultancy
Services
References
Partners
Contact
Getting Started
FAQs
Presentations
Articles
Community
Search
Popular
Tell-a-Friend
Follow Me

Follow exchangemaster on Twitter

Who's Online
We have 125 guests online
Syndicate
FAQ 000116 - Good Morning Exchange - doing a quick check on Exchange using PowerShell PDF Print E-mail
User Rating: / 29
PoorBest 
Written by Dejan Foro   
Sep 13, 2013 at 03:17 AM

This article applies to:

Exchange 2010 SP3

Windows Server 2008 R2

 

This script helps you to get a quick answer to the first question an average Exchange administrator has to answer in the morning when he comes to work:

"Can I have my morning coffee first, or is there something in Exchange that needs my immediate attention?"

 

In absence of an advanced monitoring software which would show this to you in some kind of a dashboard you can use the script given below to perfom a basic quick check : 

 

It checks the following 3 things on all your Exchange machines:

- Are Exchange services running?

- Are all databases mounted and healty?

- Are E-mails piling up in the queues?

 

Note: The part of the scripts which checks the queues can be customized by setting the value of the $MaxMessages variable in order to accomodate for your organization size / traffic patterns.

 

17.09.2013 Update to version 1.1 - service check updated to include IIS Admin and WWW Publishing Services as well.

 

<#
.NAME
    GoodMorningExchange
.VERSION
    1.1
.AUTHOR
    Dejan Foro,
    Exchangemaster GmbH, www.exchangemaster.net
.DATE
    11 September 2013
.DESCRIPTION
   The script performs a "quick check of your Exchange 2010 enviroment"
  
   It's purpose is to help you decide wheather you are OK to grab that morning coffee or
   you have things that need to be fixed before your users come into office.
  
   It checks all your Exchange 2010 servers in the Exchange organisation for the following:
   - are Exchange services running (plus IISADmin and WWW Publishing) ?
   - are all database copies healthy and mounted ?
   - are e-mails piling up in queues ?
#>


cls
Write-Host
Write-Host "Script Name: GoodMorningExchange v1.1"
Write-Host "Author: Dejan Foro, Exchangemaster GmbH, www.exchangemaster.net"
$Date = Get-Date -DisplayHint DateTime
Write-Host "Output created on: " , $Date
Write-Host


#Check if services are running
Write-Host "Checking services..."
$ThereisAProblemWithServices = $null
$ExchangeServers = Get-ExchangeServer | Sort-Object Name
Foreach ($Exchange in $ExchangeServers){
        $BadServices = Get-Service -ComputerName $Exchange.Name `
            | Select-Object DisplayName,Status `
            | where {($_.DisplayName -ilike 'Microsoft Exchange*') -and ($_.DisplayName -ne 'Microsoft Exchange Server Extension for Windows Server Backup') -or ($_.DisplayName -eq "IIS Admin Service") -or ($_.DisplayName -eq "World Wide Web Publishing Service") -and ($_.Status -ne 'Running')}
        if ($BadServices -eq $null) { }
        else {
            Write-Host $Exchange.Name
            foreach ($BadService in $BadServices){
                Write-Host $BadService.DisplayName, " " ,$BadService.Status -ForegroundColor Red
                }
            Write-Host
            $ThereIsAProblemWithServices = 1
            }
}
if ($ThereisAProblemWithServices -eq $null) {
    Write-Host "All Exchange services OK" -foregroundcolor Green
    Write-Host}


#Chek if databases are mounted and healthy
Write-Host "Checking databases.. "
$ThereIsAProblemWithDatabases = $null
$BadDatabases = Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {($_.status -ne "Healthy") -and ($_.status -ne "mounted")}`
 | Select-Object Name, Status | Sort-Object Name
if ($BadDatabases -eq $null) {}
else {
    foreach ($BadDatabase in $BadDatabases) {
    Write-Host $BadDatabase.Name $BadDatabase.Status -ForegroundColor Red
    }
    Write-Host
    $ThereIsAProblemWithDatabases = 1
   
}
if ($ThereIsAProblemWithDatabases -eq $null) {
Write-Host "All Databases OK" -ForegroundColor Green
Write-Host
}


#Check e-mail queues
#Here you can customize the max message count in queue where you consider to be a problem
Write-Host "Checking Queues..."
$MaxMessages = 2
$TransportServers = Get-ExchangeServer | where {$_.serverrole -ilike "*hubtransport*"}
$ThereIsAProblemWithQueues = $null
Foreach ($TransportServer in $TransportServers) {
    $BadQueues = Get-Queue -Server $TransportServer | where {$_.MessageCount -gt $MaxMessages}
    if ($BadQueues -eq $null) {}
    else {
        Write-Host $TransportServer.Name
        foreach ($BadQueue in $BadQueues) {
            Write-Host $BadQueue.Identity $BadQueue.MessageCount -ForegroundColor Red
            }
        Write-Host
        $ThereIsAProblemWithQueues = 1
        }
}
if ($ThereIsAProblemWithQueues -eq $null){
    Write-Host "All Queues OK" -ForegroundColor Green
    }


#If all OK go and have a coffe :)
if (($ThereIsAProblemWithServices -eq $null) -and ($ThereIsAProblemWithDatabases -eq $null) -and ($ThereIsAProblemWithQueues -eq $null)){
    Write-Host
    Write-Host "All systems OK, you can have your morning coffee :)" -ForegroundColor Green
    Write-Host
    Write-Host "   |---|" -ForegroundColor Green
    Write-Host "   |   |)" -ForegroundColor Green
    Write-Host "   |___|" -ForegroundColor Green
    Write-Host
    Write-Host
    }
else {
    Write-Host
    Write-Host "Sorry matte, no coffee for you. There is work to do."
    Write-Host
    Write-Host "   |---|" -ForegroundColor Red
    Write-Host "   |   |)" -ForegroundColor Red
    Write-Host "   |___|" -ForegroundColor Red
    Write-Host
    Write-Host
}


In case everything is fine the script will generate an output as following:

 

Script Name: GoodMorningExchange v1.1
Author: Dejan Foro, Exchangemaster GmbH, www.exchangemaster.net
Output created on:  12.09.2013 11:22:24

Checking services...
All Exchange services OK

Checking databases..
All Databases OK

Checking Queues...
All Queues OK

All systems OK, you can have your morning coffee :)

   |---|
   |   |)
   |___|

 

In case there are problems, foe example e-mails piling up in the queues the output will look as following:

 

Script Name: GoodMorningExchange v1.1
Author: Dejan Foro, Exchangemaster GmbH, www.exchangemaster.net
Output created on:  12.09.2013 11:24:40

Checking services...
All Exchange services OK

Checking databases..
All Databases OK

Checking Queues...
SERVER01
SERVER01\1448 500
SERVER01\1478 300
SERVER01\1485 50

Sorry mate, no coffee for you. There is work to do.

   |---|
   |   |)
   |___|

 

Last Updated ( Sep 20, 2013 at 08:46 AM )
<Previous   Next>