Hi Readers,
As our environment is being migrated to exchange 2010 so we have started migrating our scripts to this version as well.
This script was first written for exchange 2007 & now has been upgraded to exchange 2010 version, it is more simpler than it was before.
https://github.com/VikasSukhija/Downloads/blob/master/exchange2010healthcheck.zip
It checks the following things:-
1. PAM
2. Mailbox databases
3. Mailflow
4. Transport queues
extract the zip file & Just define the variables at the beginning of the script:
$smtphost = “smtpserver”
$from = “Exchange2010Status@LABtest.com”
$to = “Vikas.Sukhija@labtest.com”
run batch file..
below will be the kind result that you will get in your email.
Power-shell Code:-
############################################################################# # Author: Mahesh Sharma # Reviewer: Vikas SUkhija # Date: 06/10/2013 # Modified:06/19/2013 - made it to run from any path # Modified:02/09/2014 - started modifying it for exchange 2010 # Modified:02/18/2014 - modified to include all mailox servers in test mailflow # Description: ExChange Health Status ############################################################################# ########################### Add Exchange Shell############################## If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } ###########################Define Variables################################## $reportpath = ".\2010Report.htm" if((test-path $reportpath) -like $false) { new-item $reportpath -type file } $smtphost = "smtpserver" $from = "Exchange2010Status@labtest.com" $to = "vikas.sukhija@labtest.com" ###############################HTml Report Content############################ $report = $reportpath Clear-Content $report Add-Content $report "<html>" Add-Content $report "<head>" Add-Content $report "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" Add-Content $report '<title>Exchange Status Report</title>' add-content $report '<STYLE TYPE="text/css">' add-content $report "<!--" add-content $report "td {" add-content $report "font-family: Tahoma;" add-content $report "font-size: 11px;" add-content $report "border-top: 1px solid #999999;" add-content $report "border-right: 1px solid #999999;" add-content $report "border-bottom: 1px solid #999999;" add-content $report "border-left: 1px solid #999999;" add-content $report "padding-top: 0px;" add-content $report "padding-right: 0px;" add-content $report "padding-bottom: 0px;" add-content $report "padding-left: 0px;" add-content $report "}" add-content $report "body {" add-content $report "margin-left: 5px;" add-content $report "margin-top: 5px;" add-content $report "margin-right: 0px;" add-content $report "margin-bottom: 10px;" add-content $report "" add-content $report "table {" add-content $report "border: thin solid #000000;" add-content $report "}" add-content $report "-->" add-content $report "</style>" Add-Content $report "</head>" Add-Content $report "<body>" add-content $report "<table width='100%'>" add-content $report "<tr bgcolor='Lavender'>" add-content $report "<td colspan='7' height='25' align='center'>" add-content $report "<font face='tahoma' color='#003399' size='4'><strong>DAG Active Manager</strong></font>" add-content $report "</td>" add-content $report "</tr>" add-content $report "</table>" add-content $report "<table width='100%'>" Add-Content $report "<tr bgcolor='IndianRed'>" Add-Content $report "<td width='10%' align='center'><B>Identity</B></td>" Add-Content $report "<td width='5%' align='center'><B>PrimaryActiveManager</B></td>" Add-Content $report "<td width='20%' align='center'><B>OperationalMachines</B></td>" Add-Content $report "</tr>" ##############################Get ALL DAG's################################## $inputdag = Get-DatabaseAvailabilityGroup | select name ################################################################################################################ ################################################################################################################ $dagList = $inputdag $TestMailFlow = Get-ExchangeServer | where{$_.ServerRole -like "*Mailbox*"} $report = $reportpath ########################################################################################################## ##############################################Check PAM################################################### foreach ($dag in $dagList) { $dag = $dag.Name $FullStatus = Get-DatabaseAvailabilityGroup -Status $dag Foreach ($status in $Fullstatus) { $Identity = $status.identity $PrimaryActiveManager = $status.PrimaryActiveManager $Servers = $status.Servers Add-Content $report "<tr>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B> $Identity</B></td>" Add-Content $report "<td bgcolor= 'Aquamarine' align=center> <B>$PrimaryActiveManager</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$Servers</B></td>" Add-Content $report "</tr>" } } ################################################################################################################## ############################################## Mailbox Database Status ########################################### add-content $report "<tr bgcolor='Lavender'>" add-content $report "<td colspan='7' height='25' align='center'>" add-content $report "<font face='tahoma' color='#003399' size='4'><strong>Mailbox Database Status</strong></font>" add-content $report "</td>" add-content $report "</tr>" add-content $report "</tr>" add-content $report "</table>" add-content $report "<table width='100%'>" Add-Content $report "<tr bgcolor='IndianRed'>" Add-Content $report "<td width='25%' align='center'><B>databaseName</B></td>" Add-Content $report "<td width='25%' align='center'><B>Status</B></td>" Add-Content $report "<td width='25%' align='center'><B>ActiveCopy</B></td>" Add-Content $report "<td width='25%' align='center'><B>CopyQueuelength</B></td>" Add-Content $report "<td width='25%' align='center'><B>ReplayQueueLength</B></td>" Add-Content $report "<td width='25%' align='center'><B>LastInspectedLogTime</B></td>" Add-Content $report "<td width='25%' align='center'><B>ContentIndexState</B></td>" Add-Content $report "</tr>" $mbxdb = Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus foreach ($db in $mbxdb) { $dbname = $db.name $status = $db.Status $ActiveCopy = $db.ActiveCopy $CopyQueuelength = $db.CopyQueuelength $ReplayQueueLength = $db.ReplayQueueLength $LastInspectedLogTime = $db.LastInspectedLogTime $ContentIndexState = $db.ContentIndexState $result = $flow.TestMailflowResult $time = $Flow.MessageLatencyTime $remote = $Flow.IsRemoteTest Add-Content $report "<tr>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$dbname</B></td>" if (($status -eq "Mounted") -or ($status -eq "Healthy")) { Add-Content $report "<td bgcolor= 'Aquamarine' align=center> <B>$status</B></td>" } else { Add-Content $report "<td bgcolor= 'Red' align=center> <B>$status</B></td>" } Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$ActiveCopy</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$CopyQueuelength</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$ReplayQueueLength</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$LastInspectedLogTime</B></td>" if ($ContentIndexState -eq"Healthy") { Add-Content $report "<td bgcolor= 'Aquamarine' align=center> <B>$ContentIndexState</B></td>" } else { Add-Content $report "<td bgcolor= 'Red' align=center> <B>$ContentIndexState</B></td>" } Add-Content $report "</tr>" } ################################################################################################################## ############################################## Test mail Flow For DAG ############################################ add-content $report "<tr bgcolor='Lavender'>" add-content $report "<td colspan='7' height='25' align='center'>" add-content $report "<font face='tahoma' color='#003399' size='4'><strong>Mail Flow Test Report</strong></font>" add-content $report "</td>" add-content $report "</tr>" add-content $report "</tr>" add-content $report "</table>" add-content $report "<table width='100%'>" Add-Content $report "<tr bgcolor='IndianRed'>" Add-Content $report "<td width='25%' align='center'><B>Server</B></td>" Add-Content $report "<td width='25%' align='center'><B>Result</B></td>" Add-Content $report "<td width='25%' align='center'><B>Message Latency Time</B></td>" Add-Content $report "<td width='25%' align='center'><B>IsRemoteTest</B></td>" Add-Content $report "</tr>" Foreach ($server in $TestMailFlow) { $server = $server.Name write-host $server $flow = test-mailflow $server if($flow -ne $null) { $result = $flow.TestMailflowResult $time = $Flow.MessageLatencyTime $remote = $Flow.IsRemoteTest Add-Content $report "<tr>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$server</B></td>" if ($result -eq "Success") { Add-Content $report "<td bgcolor= 'Aquamarine' align=center> <B> $result</B></td>" } else { Add-Content $report "<td bgcolor= 'Red' align=center> <B> $result</B></td>" } Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$time</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$remote</B></td>" Add-Content $report "</tr>" } } ##################################################################################################################### ############################################## Get Queue For HUB Servers ############################################ add-content $report "<tr bgcolor='Lavender'>" add-content $report "<td colspan='7' height='25' align='center'>" add-content $report "<font face='tahoma' color='#003399' size='4'><strong>Mail Queue Status</strong></font>" add-content $report "</td>" add-content $report "</tr>" add-content $report "</tr>" add-content $report "</table>" add-content $report "<table width='100%'>" Add-Content $report "<tr bgcolor='IndianRed'>" Add-Content $report "<td width='25%' align='center'><B>Identity</B></td>" Add-Content $report "<td width='25%' align='center'><B>Delivery Type</B></td>" Add-Content $report "<td width='25%' align='center'><B>Status</B></td>" Add-Content $report "<td width='25%' align='center'><B>Message Count</B></td>" Add-Content $report "<td width='25%' align='center'><B>Next Hop Domain</B></td>" Add-Content $report "</tr>" $GetHub = Get-TransportServer | get-Queue Foreach ($Queue in $GetHub) { $Identity = $Queue.Identity $DeliveryType = $Queue.DeliveryType $Status = $Queue.Status $MSgCount = $Queue.Messagecount $NextHopDomain = $Queue.NextHopDomain Add-Content $report "<tr>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B> $Identity</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$DeliveryType</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$Status</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$MSgCount</B></td>" Add-Content $report "<td bgcolor= 'GainsBoro' align=center> <B>$NextHopDomain</B></td>" Add-Content $report "</tr>" } ########################################################################################################################### ######################################################### Send Mail ####################################################### Add-content $report "</table>" Add-Content $report "</body>" Add-Content $report "</html>" $subject = "Exchange Status Check Report" $body = Get-Content $reportpath $smtp= New-Object System.Net.Mail.SmtpClient $smtphost $msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body $msg.isBodyhtml = $true $smtp.send($msg) ###################################################Exchange Test Complete##################################################
Regards
Sukhija Vikas
Got the script is looking good ,when i schedule the script in task schedule, it wont generate the report . But when i generate the script through power-shell looks good. Please advice me
in the task scheduler you have to fill the optional field as well with the folder location from which script is being run…
program filed—- C:\messaging_scripts\Health Report>.\Exchange2010DailyCheckList.ps1
Addtion filed (-version4.0 -command “. ‘D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; .’D:\Health Check report\Exchange2010DailyCheckList.ps1′”)
Program filed —-C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add argument ——version4.0 -command “. ‘D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; .’C:\messaging_scripts\Health Report\Exchange2010DailyCheckList.ps1′”
Note : Report generated ,but getting blank email.,
please provide your email address
Hi, Any update on my reply , Please advice.
Just below is required:(example)
Program field: C:\Scripts\exchange2010healthcheck\exchange2010health.bat
Start in filed: C:\Scripts\exchange2010healthcheck\
Pingback: Exchange Server Health Check | Tech Wizard
Pingback: Active Directory Health Check | Tech Wizard