powershell脚本自动检核DAG

经常检查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 = "[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版本不支持原来写法。

效果如图

powershell脚本自动检核DAG,布布扣,bubuko.com

时间: 2024-08-07 21:18:24

powershell脚本自动检核DAG的相关文章

云服务程序在启动的时候执行Powershell脚本

如果在云服务程序启动时候,需要执行Powershell脚本,我们需要将脚本嵌入到程序中,并且编写一个cmd来执行这个脚本,具体如下: 1.编写测试的Powershell脚本:每隔10分钟 检测dns $TimeStart = Get-Date $TimeEnd = $timeStart.addminutes(1440) $name = "cnppmedia.blob.core.chinacloudapi.cn." $result = "d:\nslookuplog.txt&q

PowerShell 脚本执行策略

为防止恶意脚本的执行,PowerShell 中设计了一个叫做执行策略(Execution Policy)的东西(我更倾向于把它叫做脚本执行策略).我们可以在不同的应用场景中设置不同的策略来防止恶意脚本的执行.本文主要是解释这些执行策略,因为笔者在学习的时候发现它们并不是那么清晰易懂.PowerShell 提供了 Restricted.AllSigned.RemoteSigned.Unrestricted.Bypass.Undefined 六种类型的执行策略,接下来我们一一介绍. Restrict

C#调用PowerShell脚本

今天通过一个小例子,学习了C#如何调用PowerShell脚本文件的Function以及传参. private bool CallPowershell(string outputFile) { string ddcHost = "test"; RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRun

powershell脚本,命令行参数传值,并绑定变量的例子

这是小技巧文章,所以文章不长.但原创唯一,非常重要.我搜了下,还真没有人发 powershell怎样 [命令行 参数 绑定],所以我决定写成博客. 搜索关键字如下: powershell 命令行 参数 绑定 powershell 传入 参数 powershell 传递 参数 powershell CmdletBinding powershell 命令行 参数 绑定 传入 传递 parameter CmdletBinding powershell 传教士 原创文章.始于 2016-09-26 允许

PowerShell脚本授权最佳实践

[TechTarget中国原创] Windows PowerShell已成为微软在Windows Server上提供的首选管理界面.因为深度整合到Windows Server操作系统,PowerShell表面看上去可以不受任何限制做任何事情.然而,实际上能做得并没有那么多. Windows Server最好用的功能之一就是可以运行脚本.PowerShell脚本允许代码重复使用,并支持运行复杂的命令序列,这是其他方式无法实现的. PowerShell脚本的编写者必须关注的一个大问题就是授权.Pow

Powershell脚本实时获取所有cpu使用时间非0的进程

Powershell脚本实时获取所有cpu使用时间非0的进程,并将名称一致的进程合并. #定义结果输出路径 $OutFile = "D:\CPU_" + (Get-Date).GetDateTimeFormats()[1] + ".csv" #定义性能收集器对象 $CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors $Processes = Get-Counter &qu

强制PowerShell脚本以管理员权限运行

param( $a, $b ) #region 关键代码:强迫以管理员权限运行 $currentWi = [Security.Principal.WindowsIdentity]::GetCurrent() $currentWp = [Security.Principal.WindowsPrincipal]$currentWi if( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))

今天在写powershell脚本中犯的两个错误

可能是因为牙痛没睡好,今天老是犯错,还是脚本写错,特别难调. 第一个错误: powershell脚本里面,函数与函数互相调用的传参.其实就像调用普通的cmdlet一样的写法,应该这么写: Add-ScopeObject -adminAddr $adminAddr -name $newScope.Name -objectList $objectList 看我写成啥: Add-ScopeObject($adminAddr, $newScope.Name, $objectList) 结果怎么都执行不对

WindowsAzure Powershell脚本定时启动关机Azure VM

说到windowsazure对于当下不是一个新鲜话题了,但是对于功能来说还是有点期待的,毕竟在云服务的世界里windowsazure还是一个菜鸟了.同样我们都知道,对于windowsazure上的服务操作我们有很多方式可以操作,比如:portal页面,powershell with azure及azure pack等,其他的都是图形界面操作,操作相对简单,今天咱们就说说通过windows azure powershell命令来管理windows azure上的部分服务,powershell操作命