Auto Email Exchange 2007 StorageGroupCopyStatus
Posted March 12th, 2009 by Matt ShadboltExchange 2007′s Storage Group Copy feature is one of my favourites, however the one area it is really lacking is the reporting. You need to manually run the Get-StorageGroupCopyStatus -Server INITIALSERVER -StandbyMachine TARGETSERVER to find that your SCR is Healthy.
I’ve been playing around writing some simple PowerShell scripts today so I thought I would fix the reporting problem Microsoft haven’t.
I’ve written a simple PS script that gets the Status(Health), Replay Queue Length, Last Replayed Time and Last Full Backup Time and emails it to a specified address in a HTML table. Just use Task Scheduler to run this daily and you will receive the status of your SCR clusters.
You can download the script here EmailStorageGroupCopyStatusReport.ps1
Or view the script below:
#Replace the PRIMARYSERVER attribute with your production mail server, and the SECONDARYSERVER with your SCR replica
$MessageBody = Get-StorageGroupCopyStatus -Server PRIMARYSERVER -StandbyMachine SECONDARYSERVER | Select @{Expression={$_.StorageGroupName};Name=”Storage Group”}, @{Expression={$_.SummaryCopyStatus};Name=”Status”}, @{Expression={$_.ReplayQueueLength};Name=”Replay Que Length”}, @{Expression={$_.LastReplayedLogTime};Name=”Last Replayed Time”}, @{Expression={$_.LatestFullBackupTime};Name=”Last Full Backup”} | ConvertTo-Html
#Enter your mail server details
$FromAddress = “FromAddress@YourDomain.com”
$ToAddress = “ToAddress@YourDomain.com”
$MessageSubject = “Exch07 SCR Status”
$SendingServer = “MAILSERVER”
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$SMTPMessage.IsBodyHtml = $true
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
#Written by Matt Shadbolt
#http://www.mattlog.net
Tags: Exchange 2007, PowerShell, SCR, Standby Continuous Replication, StorageGroupCopyStatus
8 Responses

8 Responses to “Auto Email Exchange 2007 StorageGroupCopyStatus”
October 6th, 2009 at 6:05 am
My server will not run the script.
I have checked the security on powershell and everything seems ok. I ran the first line from the script in power shell and the get-storagegroupcopy is not recognized from powershell. any recommendations.
October 6th, 2009 at 10:27 am
You need to make sure the Exchange plugin is enabled in your PowerShell. Best way to test is to run the script from EMS first – if it works there then you add the:
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
Also, if your running the script from a PowerShell you need to set the Execution Policy correctly by:
Set-ExecutionPolicy RemoteSigned
October 14th, 2009 at 9:58 pm
Hi Matt,
This script is just what I was looking for. My only problem is that I have a 3 node cluster so I need to run this as is 3 times, i.e. 3 sets of Get-StorageGroupCopyStatus -Server PRIMARYSERVER -StandbyMachine SECONDARYSERVER.
Rather than schedule 3 separate powershells would there be an easy way to include all 3 nodes into one script and have the output dumped into one email?
Ideally each node would be headlined i.e.:
Node 1
Storage Group Status Replay Que Length Last Replayed Time Last Full Backup
SG1 Healthy 1255 10/13/2009 5:51:41 AM 10/12/2009 5:02:05 PM
SG2 Healthy 2732 10/13/2009 5:50:18 AM 10/12/2009 5:46:54 PM
Node 2
Storage Group Status Replay Que Length Last Replayed Time Last Full Backup
SG1 Healthy 1255 10/13/2009 5:51:41 AM 10/12/2009 5:02:05 PM
SG2 Healthy 2732 10/13/2009 5:50:18 AM 10/12/2009 5:46:54 PM
Node 3
Storage Group Status Replay Que Length Last Replayed Time Last Full Backup
SG1 Healthy 1255 10/13/2009 5:51:41 AM 10/12/2009 5:02:05 PM
SG2 Healthy 2732 10/13/2009 5:50:18 AM 10/12/2009 5:46:54 PM
Any help you can give is most appreciated.
Regards
Jonny Barker
October 15th, 2009 at 8:53 am
Hi Jonny,
Yeah you sould easily be able to consolidate the output into one email.
What you want to do is break out the get-storagegroupcopystatus into three variables.
ie, $NodeOneStatus = Get-StorageGroupCopyStatus NODE1..
$NodeTwoStatus = Get-StorageGroupCopyStatus NODE2..
Then pass the $NodeOneStatus and $NodeTwoStatus into the $MessageBody variable and the script will send all of the output from your $NodeOne/TwoStatus variables.
Cheers,
Matt.
October 16th, 2009 at 10:14 pm
Awesome thanks. I’ll give that a try.
Jonny
October 23rd, 2009 at 1:23 am
Hi again Matt, Just thought I’d let you know that I got my script working just the way I want it. It basically now runs the command across 3 clusters, formats the output into a readable format, dumps it to a txt file which is then attached to an email and sent. Thanks alot for you help:
$logFilePath = new-item -type file -name “$(get-date -uformat ‘%Y%m%d%H%M%S’)-filename.txt”
#Set Variables
Get-StorageGroupCopyStatus -Server servername -StandbyMachine servername | Format-Table -AutoSize | out-file $logfilepath
Get-StorageGroupCopyStatus -Server servername -StandbyMachine servername | Format-Table -AutoSize | out-file $logfilepath -append
Get-StorageGroupCopyStatus -Server servername -StandbyMachine servername | Format-Table -AutoSize | out-file $logfilepath -append
#Email function
function sendmail($attachment)
{
$SmtpClient = New-Object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$Attachment = New-Object System.Net.Mail.Attachment($logfilepath)
$SmtpClient.Host = “mailserver”
$mailmessage.from = “senders address”
$mailmessage.To.add(“recipients address”)
$mailmessage.Subject = “Storage Group Copy Status report”
$MailMessage.IsBodyHtml = $false
$mailmessage.Body = $body
$MailMessage.Attachments.Add($Attachment)
$smtpclient.Send($mailmessage)
}
sendmail $AllServers
Jonny Barker
November 10th, 2009 at 11:18 pm
Hi and thanks for this!! but Im a newbie so could you write the code for this comment:
“Hi Jonny,
Yeah you sould easily be able to consolidate the output into one email.”
And is there anyway to format the output HTML email?
You know if the status is healthy the text is green or something like that
Best regards
Robban
November 11th, 2009 at 9:51 am
Edit (seems the comment box doesn’t like html…)
————————————————-
Hi Robban,
To convert the text color to something other than red you need to use the -body switch for the ConvertTo-Html. To change all the text red use:
ConvertToHtml -body "<font color=red>"
If you only want the colour to change if the status is healthy you need to add an if statement. It shouldn’t be too hard for you to work out yourself, but here is a quick example of something simular. This script will output all processes and if the $colorred variable is set to “yes” will convert the HTML output to red:
$colorred = "yes"
If ($colorred -match "yes")
{
Get-Process |
ConvertTo-Html name,path,fileversion -title "Process Information" -body "<font color=red>"|
Set-Content C:\pscripts\test.htm
}
else
{
Get-Process |
ConvertTo-Html name,path,fileversion -title "Process Information"|
Set-Content C:\pscripts\test.htm
}
Leave a Reply