经常检查DAG复制是Exchange邮箱管理员日常任务之一,以前每天上去看也挺烦的,尤其数据库比较多的情况下。下图就是“好心”的台北同事经常提醒我检查,我的天,这要是通过EMC看还不累死。还CC我领导,搞的人怪没面子的。
图片1.jpg

几条需要注意:
一、此脚本放在exchange任一台主机运行即可。
二、Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 添加Exchange管理模块
三、用Get-MailboxDatabase |foreach name 查看公司所有的Exchange数据库,选择要监控的数据库或者全部监控

NOTES
===========================================================================
 Created with:     SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.57
 Created on:       2014/6/21 22:39
 Created by:       xing_ji
 Organization:     
 Filename:         
===========================================================================
.DESCRIPTION
    A description of the file.
#>
$host.UI.RawUI.WindowTitle = "check_DAGhealth edit by xing_ji"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
for (;;)
{
Start-Sleep -s 3600
$dblist = "XXhmdb11", "XXmdb12", "XXmdb13", "XXmdb14", "XXmdb00", "XXmdb11", "XXmdb12"
foreach ($db in $dblist)
{
    $status = Get-MailboxDatabaseCopyStatus -identity $db |foreach {$_.status}
    if ($status -notcontains "Healthy")
    {
        $msg1 = "$db is Dismount More than 5 minutes,Pls check!"
        $ssr = "relay.XXX.com"
        $from = "[email protected]"
        $to = "[email protected]"
                    $cc="[email protected]"
                $body = "$db is Dismount More than 5 minutes,Pls check!"
        Send-MailMessage -Subject $msg1 -SmtpServer $ssr -From $from -to $to -cc $cc -Body $body
    }
}
}

小插曲,
$status = (Get-MailboxDatabaseCopyStatus -identity $db).status 原先写法
$status = Get-MailboxDatabaseCopyStatus -identity $db |foreach {$_.status} 后来写法
我在写完脚本时,本机运行测试正常。但是放在服务器上运行时反而起了反作用,明明健康也给我发邮件报警玩儿。最后我发现原来是powershell 2.0版本不支持原来写法。

效果如图
图片2.jpg

标签: none

添加新评论