经常检查DAG复制是Exchange邮箱管理员日常任务之一,以前每天上去看也挺烦的,尤其数据库比较多的情况下。下图就是“好心”的台北同事经常提醒我检查,我的天,这要是通过EMC看还不累死。还CC我领导,搞的人怪没面子的。
几条需要注意:
一、此脚本放在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 = "WhatsUpGold@XXX.com" $to = "xing_ji@XXX.com" $cc="XXX@XXX.com" $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版本不支持原来写法。
效果如图
本文出自 “杂谈” 博客,请务必保留此出处http://jixing.blog.51cto.com/821242/1429450
powershell脚本自动检核DAG,布布扣,bubuko.com
原文地址:http://jixing.blog.51cto.com/821242/1429450