码迷,mamicode.com
首页 > 数据库 > 详细

检查邮箱数据库状态并生成报表脚本

时间:2018-12-27 13:30:49      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:src   health   order   ack   信息   需要   img   body   erro   

此脚本是群里面的哥们共享的,本人特整理出来分享给有需要的同学。

注意:
1.使用前修改下里面的一些参数(原作者都贴心的标注了)
2.有必要的话修改下脚本的执行策略

效果截图:
技术分享图片

计划任务截图:
技术分享图片

脚本内容:

add-pssnapin microsoft.exchange* #加载EMS不然exchange命令无法识别

$Smtp="mail.demo.com"#需要修改的地方br/>$AdminEamil="zhangdl@demo.com,zhangsan@demo.com"#需要修改的地方
$EmailSender="zhangdl@demo.com"#需要修改的地方
$i=0
$Searcher = Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus
$bordercolor = ‘#eee‘
$i = 0
foreach($Sear in $Searcher)
{
#$MailDB = Get-MailboxDatabase -Identity $Sear.Databasename
$sem = ‘无‘
$bgindex = ‘‘
$trbgcolor = ‘‘
$errmess = ‘‘
#判断库的复制和装入状态
if ($Sear.Status -eq ‘Healthy‘)
{$SStatus = ‘复制正常‘#状态,如已装载
$bordercolor = ‘#efefef‘
}
Elseif($Sear.Status -eq ‘Suspended‘)
{
$SStatus = ‘已搁置‘
$bordercolor = ‘#FFFFCC‘
}
Elseif($Sear.Status -eq ‘Failed‘)
{
$SStatus = ‘失败‘
$bordercolor = ‘#FF0000‘
}
Elseif($Sear.Status -eq ‘Mounted‘)
{
$SStatus = ‘已装载‘
$bordercolor = ‘#ffffff‘
}
Elseif($Sear.Status -eq ‘Dismounted‘)
{
$SStatus = ‘已卸载‘
$bordercolor = ‘#ffcc00‘
}
Elseif($Sear.Status -eq ‘ServiceDown‘)
{
$SStatus = ‘服务停止‘
$bordercolor = ‘#FF0000‘
}
else
{
$SStatus = $Sear.Status
}
#判断内容索引状态
if ($Sear.ContentIndexState -eq ‘Healthy‘)
{
$SConIndexState = ‘正常‘
}
elseif ($Sear.ContentIndexState -eq ‘Failed‘)
{
$SConIndexState = ‘失败‘
$bgindex = ‘#ff0000‘
}
else
{
$SConIndexState = $Sear.ContentIndexState
$bgindex = ‘#ff0000‘
}
#判断是否有错误
if ($Sear.ErrorMessage.length -gt 0)
{
$i = $i+1
$sem = ‘错误代码00‘+$i
$errmess = $Sear.ErrorMessage
$errmes += "<tr style=""font-size:12px; font-family:‘微软雅黑‘;$trbgcolor"" align=""center"">
<td height=""30"">$sem</td>
<td align=""left"">$errmess</td></tr>"
}
#判断是否为主库
if ($Sear.ActiveCopy -eq $true)
{
$sac = ‘是‘
}
else
{
$sac = ‘否‘
$trbgcolor = ‘background-color:#efefef‘
}
$mbs = $Sear.MailboxServer
$sdn = $Sear.DatabaseName
$scql = $Sear.CopyQueueLength
$srql = $Sear.ReplayQueueLength

    $seei = $Sear.ErrorEventId
    $OutDB += "<tr style=""font-size:12px; font-family:‘微软雅黑‘;$trbgcolor"" align=""center"">
<td height=""30"">$mbs</td>
<td>$sdn</td>
<td bgcolor=""$bordercolor"">??$SStatus??</td>
<td bgcolor=""$bgindex"">??$SConIndexState??</td>
<td>??$scql??</td>
<td>??$srql??</td>
<td>??$sac??</td>
<td bgcolor=""$bordercolor"">??$sem??</td>
<td>??$seei??</td>

</tr>"
}
$Output = "<font size=""1"" face=""Arial,sans-serif"">
<h3 align=""center"">Exchange 数据库运行状态报表</h3>
<h5 align=""center"">生成时间 $((Get-Date).ToString())</h5>
</font>
<table width=""100%"" bordercolor=""#FFFFFF"" border=""0"" cellspacing=""2"" cellpadding=""0"">
<tr style=""background-color:#090; color:#FFF; font-size:14px; font-family:‘微软雅黑‘;"" align=""center"">
<td height=""30"">服务器名称</td>
<td>数据库名称</td>
<td>状态</td>
<td>内容索引状态</td>
<td>复制队列长度</td>
<td>重播队列长度</td>
<td>是否为主动库</td>
<td>错误信息</td>
<td>错误事件ID</td>
</tr>
$OutDB
</table>
<br><br><h5 align=""center"">错误代码及错误信息</h5><br>
<table width=""100%"" bordercolor=""#FFFFFF"" border=""0"" cellspacing=""2"" cellpadding=""0"">
<tr style=""background-color:#f90; color:#FFF; font-size:14px; font-family:‘微软雅黑‘;"" align=""center"">
<td>错误代码</td>
<td>错误内容</td>
</tr>
$errmes
</table>
"

function sendmail($body)
{
$today = Get-Date
$SmtpClient = new-object system.net.mail.smtpClient
$mailmessage = New-Object system.net.mail.mailmessage

$SmtpClient.Host = $Smtp
$mailmessage.from = $EmailSender
$mailmessage.To.add($AdminEamil)
$mailmessage.Priority=[system.net.mail.MailPriority]::High  
$mailmessage.Bcc.add("zhangdl@qunar.com") #需要修改处
$mailmessage.Subject = “[Report] Exchange 数据库运行状态报表” 
$mailmessage.IsBodyHtml = $true
$mailmessage.Body += "`n" +  $body

$smtpclient.Send($mailmessage) 

}
sendmail $Output

检查邮箱数据库状态并生成报表脚本

标签:src   health   order   ack   信息   需要   img   body   erro   

原文地址:http://blog.51cto.com/seawind/2335919

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!