I need to get the exchange server in our lab up so I can test some of the cool PowerShell scripts I’ve been finding for Exchange. Today I found scripts to do Exchange monitoring that look like they would work very nicely with PowerWF for SCOM. The article contains 4 PowerShell scripts:
Check CPU Utilisation
The check_CPU function within the script is designed to connect remotely to the WMI namespace of an Exchange Server and retrieve a sample value (typically the last minute) of current CPU utilisation (this is per CPU or per CPU / Per Core).
…
functioncheck_CPU(){
Foreach ($exMacin$ExServers){
$cpuS=Get-WmiObject-ComputerName$exMacWin32_Processor
Write-Host“Checking $exMac CPU Load”-ForegroundColorGreen
foreach ($procin$cpuS){
Write-Host“Checking CPU: $proc”
Write-Host$proc.LoadPercentage -ForegroundColorWhite
If($proc.LoadPercentage -gt$CPU_UpperLeverPercentage){
$procTot=$proc.LoadPercentage
$MessBody=”<b>Exchange Server CPU Load for $proc is over defined threshold of $CPU_UpperLeverPercentage with a value of $procTot for the sample period</b>”
SMTPAlertMessage”Exchange CPU is over threshold size”$MessBody
}
}
}
}
Check Memory Utilisation
The check_Mem function within the script is designed to connect remotely to the WMI namespace of an Exchange Server and retrieve a value of the current amount of RAM which is free.
…
functioncheck_Mem(){
Foreach ($exMacin$ExServers){
$AvailMem=Get-WmiObject-ComputerName$exMacWin32_PerfFormattedData_PerfOS_Memory
If($AvailMem.AvailableMBytes -lt$MemoryThreshold){
$detMem=$AvailMem.AvailableMBytes
$MessBody=”<b>Exchange Server Memory Load is less than defined threshold of $MemoryThreshold with a value of $detMem MBs for the sample period</b>”
SMTPAlertMessage”Exchange Available Memory is lower than threshold size”$MessBody
}
}
}
Get Error Events Function
The purpose of the Error Events function is to retrieve the last 10 error events which are Exchange related from the Application Event log on the target server.
…
functionget_ErrorEvents($strServer){
$Events=Get-EventLog-computer$strServer-LogName”Application”-EntryType”Error” | where {$_.Source -like”*Exchange*”}
# Count the number of errors
$Count= 0
$MessageBody=”<H1>Exchange Related Events</H1><hr><p>There are more than 10 Error events related to Exchange in the Application Event Log - you should review this</p><hr>”
foreach($evtin$Events){
$Count++
}
if ($Count-gt 10){
$retEvents=Get-EventLog-computer$strServer-LogName”Application”-EntryType”Error”-Newest 10 | where {$_.Source -like”*Exchange*”}
foreach($rEvtin$retEvents){
$MessageBody=$MessageBody+”<p><h2>”+$rEvt.EntryType +”</h2></p><p><h3>”+$rEvt.Source +”</h3></p><p>”+$rEvt.Message +”</p>”
}
SMTPAlertMessage”Exchange Server Event Issues”$MessageBody
}
}
Check Roles Function
The purpose of the checkRoles function is to detect which Exchange Roles are resident on the Exchange Server which is passed from the ExchangeServers.txt file. When the roles for each server have been determined – the appropriate testing function is called (we will begin to cover these in part 3). The checkRoles function also calls the get_ErrorEvents function.
…
functioncheckRoles(){
Foreach($exMacin$ExServers){
$roleTest=Get-ExchangeServer$exMac
Write-Host“Checking Events on: $exMac”-ForegroundColorMagenta
get_ErrorEvents$exMac
if($roleTest.isMailboxServer -eq$true){
Write-Host“Mailbox Role Detected”-ForegroundColorYellow
mailBoxRoleTests$exMac# Defined in the next part
}
if($roleTest.isHubTransportServer -eq$true){
Write-Host“HT Role Detected”-ForegroundColorYellow
HTRoleTest$exMac# Defined in the next part
}
if($roleTest.isClientAccessServer -eq$true){
Write-Host“CAS Role Detected”-ForegroundColorYellow
CASRoleTest$exMac# Defined in the next part
}
}
}