Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Script to show failed databases and send an email

$
0
0

Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4

Hi

I usually check all the databases in the DAG to make sure there are none that have failed or suspended. The command i use is crude but works and displays the name e.g

db1\server1  failed suspended

db5\server4  suspended

db17\server6 failed

get-mailboxserver |Get-MailboxDatabaseCopyStatus |? {$_.status -ne"healthy"} |? {$_.status -ne "mounted"} | Sort-Object databasename

 

I wanted to just automate this and sent an emailing  me a list of all failed databases name/server and if there are no failed databases to tell me there are none.

Being a total novice i tried this and failed any help would be really great

 

$servers=get-mailboxserver

$dbcopystatus=$servers|Get-MailboxDatabaseCopyStatus

$nothealthy=$dbcopystatus|? {$_.status -ne"healthy"}

$nomounted=$nothealthy|? {$_.status -n e "mounted"}

$faulty=$nomounted| Sort-Object databasename

$output = If (@($faulty).count > 0)

    { Write-output “Failed disk $faulty"`n"}

    Else

    {  Write-output“No Disks are faulty”  `n"    }

 

Send-MailMessage -from "Exchange2010@abc.com" -to "admin@xyz.com" -Subject "bad db disk $((get-date).ToShortDateString())" -body $output -bodyashtml -SmtpServer"SMTP" -Priority high

 

Thanks

ian


Viewing all articles
Browse latest Browse all 6937

Trending Articles