此脚本是群里面的哥们共享的,本人特整理出来分享给有需要的同学。
注意:
1.使用前修改下里面的一些参数(原作者都贴心的标注了)
2.有必要的话修改下脚本的执行策略
效果截图:
计划任务截图:
脚本内容:
add-pssnapin microsoft.exchange* #加载EMS不然exchange命令无法识别
$Smtp="mail.demo.com"#需要修改的地方$AdminEamil="zhangdl@demo.com,zhangsan@demo.com"#需要修改的地方
br/>$AdminEamil="zhangdl@demo.com,zhangsan@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 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"">
<h4 align=""center"">Exchange 数据库运行状态报表</h4>
<h6 align=""center"">生成时间 $((Get-Date).ToString())</h6>
</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><h6 align=""center"">错误代码及错误信息</h6><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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。