切换到宽版
  • 9648阅读
  • 0回复

[求助]使用脚本检测组织中的Exchange服务器健康状况 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-19
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:PowerShell
  • 适合版本:Exchange 2007
  • 适用平台:
########################################################################################
#Date:25 Oct  2010
#Script:Checkexhealth.ps1
#Description:Check services on Exchange servers and check Queue status of transport servers
#Sends out an email if it finds some issue
#
#
#
########################################################################################
$probfound=""


Function docheck ($a)
{
    clear
    Write-host ""
    Write-host "Server Name:" $a.name -ForegroundColor Yellow
    Write-host "Server Role:" $a.ServerRole -ForegroundColor Green
    Write-Host "Running service health Check"
    $o1=Test-ServiceHealth $a.name|where {$_.requiredservicesrunning -eq $false}
    
    
        if ($o1 -ne $null)
        {
            $script:probfound += "<TR bgcolor=cyan><TD><p align=center> Problem Found with services on <b>" + $a.Name + " </b> with these server roles <i>" + $a.serverrole + ".</i> </TD></TR>"
            $script:probfound += "<TR><TD><p align=center><font size=2 color=red ><i>" + $($o1.servicesnotrunning ) + " </i> </font>is not running.</TD><TR>"
        }
        if ($a.IsHubTransportServer -eq $true)
        {
            Write-Host "Getting Queue (Queues in Retry state)  Info.."
            $o2=Get-Queue -Server $a.Name -filter {status -eq "retry"} -ResultSize unlimited
            if ($o2 -ne $null)
            {
                
                $script:probfound+=  "<TR bgcolor=cyan><TD><p align=center>" + "Problem Found with <b>" + $a.Name + " </b> with these Queues in Retry State. </TD></TR>"
                foreach ($q in $o2)
                {
                $script:probfound+= "<TR><TD><p align=center>" + $($q.identity.toString()) + " with next hop domain " + $($q.nexthopdomain.tostring()) + "<font size =2 color=red> (" + $q.messagecount + ")</font><br></TD></TR>"
                }
            }
        }    
    
    
}


Function emailsend
{
$probfoundhead="<HTML><BODY><TABLE align=center cellspacing=0 bordercolor=black border=1>"
$emailFrom = "Mail From field"
$emailTo = "Email Address To field"
$subject = "Exchange servers status"
$script:probfound+="</Table></Body></HTML>"
$body = $probfoundhead + $script:probfound
$smtpServer = "SMTP server name"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $body.ToString())
$msg.IsBodyHTML = $true
$smtp.Send($msg)


}


Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
if ($($args.count) -ne 0)
{
    $standalonever=$true
    foreach ($svr in $args)
    {
    docheck (get-ExchangeServer $svr)
    
    }
}
else
{


    
    foreach ($a2 in (get-exchangeserver))
    {
        docheck $a2
    }
}




if ($probfound.Length -ne 0)
{
    if ($standalonever -ne $true)
    {
        emailsend
    }
    else
    {
        $probhtml="<HTML><BODY><TABLE align=center cellspacing=0 bordercolor=black border=1>" + $probfound + "</Table></Body></HTML>"
        $probhtml|out-file exchangeservicehealth.htm
        invoke-expression .\exchangeservicehealth.htm
    }
}
else
{
    Write-Host "All is well :)"
}
分享到
快速回复
限60 字节
 
上一个 下一个